Live data from Hacker News

Stronger Shell

m.odul.us

1–10 of 80 posts

Re: Stronger Shell

#2
How many people learned shell scripting while engaged in morally ambiguous activities? For me it was scraping for porn ~25 years ago. I imagine lots of people learned scripting while "penetration testing".

Re: Stronger Shell

#4
> You must have spaces inside your test expressions (so [[-z $FOO]] won't work; [[ -z $FOO ]] is correct).

That's because '[[' is a special bash extension which started out as a better '[' which is actually a binary (/usr/bin/[). And, well, you have to have a space between an executable and its first argument.

(nowadays '[' and '[[' are builtins in most shells, but the external binary still exists).

Re: Stronger Shell

#5
I'd be remiss if I didn't use the comments to mention the amazing and totally free, "Unix for the Beginning Mage". The author of the article also didn't mention this great resource. It's an amazing book and a short read. It took me about 3 hours to work through completely. www.unixmages.com

If you don't know how to use your shell, block yourself off an evening with this book and change how you forever use you computer.

Re: Stronger Shell

#7
If you're writing shell scripts, you might as well write Ansible playbooks. You can use Ansible playbooks locally without the SSH layer.

Bash/sh is a horrible programming language.

Re: Stronger Shell

#8
post #6

I personally can't stand bash for writing scripts (it's fine for typing one-liners into terminal though). This question and its top answer capture the insanity of bash quite nicely http://stackoverflow.com/questions/3601515/how-to-check-if-a... .

Is there a better shell? By which I mean more flexible, more consistent, and simpler. (Anyone who says 'zsh' is disqualified.)

I've briefly looked at rc, but while it's significantly simpler and more orthogonal than sh it's got it's own weirdnesses; but the 'Design Principles' section here is worth reading: http://plan9.bell-labs.com/sys/doc/rc.html

Surely there must be a usable shell wrapped around an actual modern language?

Re: Stronger Shell

#9
You don't need to learn Bash to write shell scripts. Many other languages support executing commands with special syntax (PHP and Perl have backticks for example).

I write my scripts in PHP if they're moderately complex, and only use Bash for dumb lists of commands.

Re: Stronger Shell

#10
post #6

I personally can't stand bash for writing scripts (it's fine for typing one-liners into terminal though). This question and its top answer capture the insanity of bash quite nicely http://stackoverflow.com/questions/3601515/how-to-check-if-a... .

Is there a better shell? By which I mean more flexible, more consistent, and simpler. (Anyone who says 'zsh' is disqualified.) I've briefly looked at rc, but while it's significantly simpler and more orthogonal than sh it's got it's own weirdnesses; but the 'Design Principles' section here is worth reading: http://plan9.bell-labs.com/sys/doc/rc.html Surely there must be a usable shell wrapped around an actual modern…

I like xonsh.

http://xonsh.org/

It has two modes, which can be a bit confusing. A python mode and a bash-ish mode.

    testdata = $(ls -l) #Takes thes bash command 'ls -l' and saves it to the python variable testdata

    echo ${testdata.upper()} | grep XLIO

    $(ls).split("\n")
It uses some magic to figure out whether you're in a python context or a bash context, defaulting to python. If you save some stuff to a variable called "ls", you need to del(ls) before you can use ls as a command again.
Post reply on HN