
Explain Shell - aleem
http://explainshell.com/
======
sjrd
_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.

~~~
tsneed290
TIL that git calls itself "the stupid content tracker"

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

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

------
bradbeattie
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?

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

------
dang
Two big threads from 2013:

[https://news.ycombinator.com/item?id=6296634](https://news.ycombinator.com/item?id=6296634)

[https://news.ycombinator.com/item?id=6834791](https://news.ycombinator.com/item?id=6834791)

~~~
idank
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!

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

~~~
zoidb
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](https://cmdchallenge.com)

------
The_Hoff
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).

~~~
boramalper
> 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.

~~~
idank
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. :)

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

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

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

~~~
moxious
:) 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?

~~~
nonsince
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.

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

------
tmerr
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

~~~
tomjakubowski
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.

------
mabynogy
Optenum to enrich the database of arguments:

[https://github.com/mattboyer/optenum](https://github.com/mattboyer/optenum)

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

------
fbis251
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

------
TeMPOraL
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.

------
tdrd
Really solid. I fed it a recent nasty line from our Makefile:
[https://github.com/cockroachdb/cockroach/blob/4aeef50/build/...](https://github.com/cockroachdb/cockroach/blob/4aeef50/build/protobuf.mk#L132)

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

[http://explainshell.com/explain?cmd=find+.+-name+*.pb.cc+%7C...](http://explainshell.com/explain?cmd=find+.+-name+*.pb.cc+%7C+sed+%27s%21.%2F%21%21%27+%7C+xargs+-I+%25+sh+-c+%27echo+%22%23include+%5C%22%25%5C%22%22+%3E+%24%28echo+%25+%7C+tr+%2F+_%29%27)

------
btschaegg
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%...](http://explainshell.com/explain?cmd=dd+if%3D%2Fdev%2Fsda+of%3D%2Fdev%2Fsdb)

Edit:

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+127.0.0.1+-p+80](http://explainshell.com/explain?cmd=nc+127.0.0.1+-p+80)

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

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

~~~
umanwizard
How so?

------
kevincox
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.

~~~
idank
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

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

------
augustt
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...](http://explainshell.com/explain?cmd=gcc+-I%2Fusr%2Flocal%2Finclude+-L%2Fusers%2Fblah%2Flibs+test.c+-o+bin%2Fprogram)

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

echo $(( 1 + 2 ))

~~~
phaemon
It's actually POSIX standard. See
[http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3...](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04)

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

------
danellis
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.

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

~~~
danellis
I thought I just did.

------
JasonSage
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.

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

~~~
jandy
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.

~~~
btschaegg
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).

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

~~~
idank
[[ seems broken but this works

[http://explainshell.com/explain?cmd=%5B+-f+foo](http://explainshell.com/explain?cmd=%5B+-f+foo)

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

------
scott_karana

      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"`

------
tuxxy
It doesn't quite get dd, as well.

[http://explainshell.com/explain?cmd=dd+if%3D%2Fdev%2Furandom...](http://explainshell.com/explain?cmd=dd+if%3D%2Fdev%2Furandom+of%3Dtest.iso+bs%3D10M+count%3D10)

~~~
cat199
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.

[https://news.ycombinator.com/item?id=13896675](https://news.ycombinator.com/item?id=13896675)

~~~
bigbugbag
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.

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

------
rohit33
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.

------
transposed
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.

------
elmigranto
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).

------
nevster
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.)

------
israrkhan
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.

~~~
zamalek
Regex101[1] does a pretty good job.

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

------
holtalanm
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.

------
mtrycz
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...

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

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

e.g. _explain cat foo.txt > out.txt_

~~~
Ajedi32
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.

~~~
rena-anju
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.

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

[http://explainshell.com/explain?cmd=sudo+make+me+a+sandwich](http://explainshell.com/explain?cmd=sudo+make+me+a+sandwich)

------
tambourine_man
Nice work, could have a better mobile layout, though

------
rmist
rtfm

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

[http://explainshell.com/explain?cmd=Get-
ChildItem](http://explainshell.com/explain?cmd=Get-ChildItem)

~~~
ldd
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)

~~~
arca_vorago
>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)

