Hacker News new | comments | show | ask | jobs | submit login
Explain Shell (explainshell.com)
775 points by aleem 27 days ago | hide | past | web | 85 comments | favorite

Very nice! I fed it one of my favorite commands:

    git branch --merged | grep -v master | xargs -n 1 git branch -d
and it dealt with it reasonably well. The only part it couldn't understand was `branch -d` at the end. In other words, it was not capable of recognizing that the non-option arguments to `xargs` should actually be recursively interpreted as a command-line.

TIL that git calls itself "the stupid content tracker"

Pretty funny seeing as the main complaint about git is that it's too complex

I also tried a command with xargs, it seemed to do a pretty good job: http://explainshell.com/explain?cmd=find+.+-type+f+-print0+%...

Best used in combination with shellcheck (https://www.shellcheck.net/), which checks your shell scripts for bugs.

I fed it the most recent command posted on commandlinefu.com:

    grep -i s2enc /etc/vcac/server.xml | sed -e 's/.* password=\"\([^\"]*\)\".*/\1/' | xargs -n 1 vcac-config prop-util -d --p 2>/dev/null; echo
Given the height of the result, scrolling up and down became a real pain. Maybe collapsable sections or position:fixed for the command or something like that?

The "navigate:" part lets you cycle through 'chunks' of explanations

Wow it's been 4 years?

Would you believe it if I told you it's running on the smallest digital ocean instance, backed by MongoDB (!), and the only time I had to do any maintenance on it was when DO turned down the machine I happened to run on? The service doesn't exactly scream complexity, but it's nice when you put something out there and it just runs!

A quick shout out that I use explain shell in my teaching kids how unix and piping functions work. Cheers man!

I wrote a little shell challenge/tutorial project a little bit ago and was thinking about adapting it to teaching beginners. would love to hear your thoughts -https://cmdchallenge.com

Didn't know about this, thanks for reposting!

I would love it if the site was encrypted so that I could input raw commands at work without modifying sensitive information. (Yes I understand the host can still record this sensitive information, and no I have not looked through the source code yet to see that this doesn't occur).

> and no I have not looked through the source code yet to see that this doesn't occur

Still, the website might be running on a modified version.

It doesn't. And I'm not just saying that because there's an agent pointing a gun at me as I type this.

Having said that, please don't send sensitive information to a random service on the internet. :)

No offense, I was just pointing a general fact. =)

Well, it's open-source so I guess you could always self-host.

Quite Nice. Just FYI, the very first command, :(){ :|:& };: is a fork bomb and you probably shouldn't run it in your shell

Wish I'd read your comment beforehand. Tried it blindly and and lost about 10 min trying to figure out what was happening ...

:) Well I'm tempted to chide you for running arbitrary code from the Internet from an untrusted source, but then I remember that's the entire web via JavaScript and I realize I'm living in a glass house.

Who came up with this security model anyway?

At least JavaScript's immune to fork bombs because it has no threading model. Doesn't stop some bored college kid with access to NPM and a vicious streak from mining bitcoin on your computer.

That's not true, JS has Web Workers. But they're threads, not processes, and perhaps the browser will throttle them.

In my defense, it appeared to be a harmless looking sequence of special characters (not quite, as I found to my dismay). Explain Shell didn't help much

Which is easily blocked by having sensible ulimits. Too bad they are always at zero (no limits.)

This works well, but the web interface seems like an unnecessary layer on top of what could just be a terminal based tool. I'm trying to resist the urge to fork this, putting another project on my todo list I will never finish

The lines connecting each explanation to the relevant part of the command line could be tricky to squeeze into a terminal window. You'd could instead create an interface with a movable "cursor", which highlights a single "chunk" of the command line, and presents the explanation for that "chunk" beneath the entire command line string.

I have a little bash script I picked up somewhere that uses mankier.com to a similar effect:

  explain () {
      if [ "$#" -eq 0 ]
          while read -p "Command: " cmd
              curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$cmd"
          echo "Bye!"
      elif [ "$#" -eq 1 ]
          curl -Gs "https://www.mankier.com/api/explain/?cols="$(tput cols) --data-urlencode "q=$1"
          echo "Usage"
          echo "explain                  interactive mode."
          echo "explain 'cmd -o | ...'   one quoted command to explain it."

Optenum to enrich the database of arguments:


Readme says it works with bash autocompletion, does it work with zsh autocompletion ?

Oh yeah - this would be a great addition to an already great serivce.

Does anyone know where I can find a completely offline tool that does what this site does?

The source for this seems like a bit of overkill. I'd like to be able to use a cli based tool that shows me relevant man sections for the flags I chose for example

Lovely! Bookmarking for future use!

Some quick notes on my way back from work:

1. Broken on mobile :(. Default layout is a mess, and "request desktop site" has the lines going to the edge of the screen, making them invisible. S7, Android, Firefox.

2. Totally neeeds to be done as an Emacs mode (preferably offline). Both for checking a particular command and during writing shell scripts.

Really solid. I fed it a recent nasty line from our Makefile: https://github.com/cockroachdb/cockroach/blob/4aeef50/build/...

Looks like it doesn't deal with subshells, but otherwise it did reasonably well.


Very impressive.

It seems to rely strongly on common *NIX CLI patterns though. It really doesn't like dd, for example[1].

[1]: http://explainshell.com/explain?cmd=dd+if%3D%2Fdev%2Fsda+of%...


Also, it doesn't understand that the token after `-p` for netcat is actually the port argument[2]. I guess it is parsing manpages internally?

[2]: http://explainshell.com/explain?cmd=nc+

It boils down to a bunch of heuristics so there are gaps if the man page is slightly off of what it expects.

I'm not saying that this _is_ a phishing scam. But if it is, hoo boy it's a clever one.

How so?

Cool tool. I think what would really be the icing on the cake is if it substitued the actual command into the documentation. Removing that one layer of indirection would make it that much easier to understand.

For example:

foo() { bar }

> This defines a function named "foo".

Also that example fails to parse. Even though :() { :|: };: works so it seems like there is a certian amount of special casing.

That's an awesome idea. I'd love to try that one day.

Your command isn't valid because it's missing a control character after 'bar', such as ';'. Bash rejects it as well:

  $ bash -c "foo() { bar }"
  bash: -c: line 1: syntax error: unexpected end of file

Oops, you are right, that's what I get for testing on zsh :(

Very cool! Although it has some problems if there isn't a space between a flag and its value: http://explainshell.com/explain?cmd=gcc+-I%2Fusr%2Flocal%2Fi...

Pretty awesome, but broke on the first command I tried (granted, it is bash specific IIRC)

echo $(( 1 + 2 ))

However, the site does interpret input as bash and not a Posix-compliant shell.

not at all a bashism

  $ uname -sr
  OpenBSD 6.0
  $ ps T
  85828 pc  Ssp     0:00.01 -ksh (ksh)
  34802 pc  R+p     0:00.00 ps -T
  $ echo $(( 1 + 2 ))    

Resident bsd hero

    % /bin/sh
    $ echo $((1 + 2))
    $ uname -srm
    DragonFly 4.7-DEVELOPMENT x86_64

If you hover over something that points to a description that's not currently in view, you can't scroll to the description without unhovering and hence unhighlighting the line pointing to the right description.

How do you mean? Seems to work for me. Please file a bug report with how to reproduce!

I thought I just did.

There are several commands on OS X that behave a bit differently from their traditional UNIX counterparts. grep is the big one that springs to mind—any given grep shell-fu may just not work on OS X and I'll find myself having to reconstruct the arguments from scratch to get it working.

I'd love to see a fork of explainshell or an option in the interface to deal with items like this which are specific to OS X. Let me put a grep command in for OS X and have it show me what options I'm using which are undocumented—that would be nifty.

By "traditional UNIX" do you mean GNU specifically? What on macOS differs more from standards than does the typical Linux distro?

Not OP, but one I came across yesterday was `date`.

Linux: `date -d '10 mins ago'` Mac: `date -v -10M`

There's loads of tiny differences like this. Often just old versions, and you can pull in the latest with `brew` or something.

Another one is GNU find assuming the current directory if omitted, while BSD find explicitely has to be told the directory to search in.

It's nothing complicated, but breaks many scripts if you only test them on Linux (more or less the same problem like case-insensitive filesystems).

I'll have to add, though, that one could argue that OSX is the one behaving like "traditional UNIX", since most of it's tools derive from BSD-Versions. GNU tools are the ones that deviate from this (which I still find more convenient in day to day use).

Sure, I know there are lots of differences between GNU and macOS; that's not what I'm asking about.

The BSD coreutils that macOS uses are much more "traditional UNIX" than the GNU coreutils.

Has anyone been able to get [ or [[ to work here?

[[ seems broken but this works


As a relatively new programmer and one who went to one of those mediocre bootcamps, resources like this are invaluable. Thanks!

  file=$(echo `basename "$file"`)
This is a horrible example, since it has a "useless use of echo", forcing nested evaluations and a bashism. Basename prints to stdout too!

The sh-compatible, simpler equivalent:

  file=`basename "$file"`

Didn't you hear? dd is a 'cult', and you should use 'standard' commands like pv instead, so this is totally okay, in fact good.


First comment from your link debunks the whole ordeal. pv is for monitoring the progress of data going through a pipe, hardly related to dd.

Pretty sweet! It's not explaining the 'u' in: netstat -tulpn though :O

Does well, but goes only so far. I fed the command sudo chown -R $USER:$USER /var/www/example.com/html and the tool wasn't capable of recognizing what $USER:$USER is doing.

I thought this was pretty cool but missing something. Until I realized that uMatrix was blocking Cloudflare. Once I loaded the rest of the site... Awesomeness. Great work, whoever made this.

Pretty neat! Though it would be nice if it brought into the view the part you highlight when it doesn't fit on screen, otherwise you have to scroll (and highlight is lost).

Handy tip for those on a mac using terminal - type a command and press cmd-ctrl-shift-? to get a man page pop-up. (People with touch bars can just tap on the man page icon.)

Very nice. However I find myself trying to decipher regular expressions more often than shell commands. A tool like this for regular expressions would have been more useful.

Regex101[1] does a pretty good job.

[1]: https://regex101.com/

i discovered this site about two years ago. I still use it for explaining commands that I run across on StackOverflow before I run them in my own terminal.

I totally love this, expecially for learning other peoples code and habits.

If it only had a CLI so that I could use it directly from my terminal...

Even though I'm fairly experienced in bash, this is the ultimate cheat sheet we all need. Thank you!

Too bad, I hoped this was a shell util like EXPLAIN in SQL.

e.g. explain cat foo.txt > out.txt

All it needs is an API and you could easily build a tool which does just that.

Though if you wanted it to actually explain `cat foo.txt > out.txt` and not just output the explanation for `cat foo.txt` to `out.txt` you'd probably have to put that in quotes.

Not really need an API to quickly build a tool for this. Could as well just send a proper request and parse the response, not too much of extra work for this service.

it does a pretty good job with "sudo make me a sandwich" =)



Nice work, could have a better mobile layout, though

There's no PowerShell support. That's not any command.


I'm confused. Is PowerShell 'recognized' as a shell?

I thought only unix and unix-like shells would be covered. I wonder what the technical definition of a shell is though.

(genuinely curious, not trying to be snarky)

>I'm confused. Is PowerShell 'recognized' as a shell?

Yes, given the definiton of shell being a user interface to an operating system, typically command line, powershell is considered a shell and can function as one. For example, while many think of windows servers as being all gui, newer versions of windows (server) can be run entirely in cli mode with no gui via powershell, in which supposedly any management technique normally done through gui can be done through the ps cli.

The main difference between nix shells and powershell is that the nix shells are text based, while powershell is object based due to it's .NET core.

As a sysadmin who uses both bash and powershell, I have to say the more recent versions of powershell are quite powerful and a fresh breath of air to use in the normally stale windows world. Of course, I tend to use pywinrm to remotely run ps commands so I don't too dirty touching the tainted MS ecosystem. (That's my way of saying that while powershell is nice and a large improvement over batch command line files, bash is still the better one due to the underlying unix philosophy and the GNU ecosystem)

Yes, it is recognized as a shell.

The original description was listed as "explain any shell command". That was an erroneous title that's since been updated.

It clearly doesn't cover "unix and unix-like" shells, since fish shell syntax isn't supported. It seems to be trying to be bash-compatible since it uses bashlex under the hood, but as another commented noticed, the bash parsing isn't perfect.

It depends who's doing the recognizing. I don't see why it wouldn't. And I'm not sure where you got the idea that it was unix-likes only.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact