Live data from Hacker News

Ask HN: How do I become a shell god?

news.ycombinator.com

21–30 of 34 posts

Re: Ask HN: How do I become a shell god?

#21
post #10

My way is: Try to write small loops and pipes on the command line. I do things like this all the time: for i in foo*.txt; do mv $i OLD-$i; done You'll find this breaks sometimes, so use control-r to recall the command and fix it for i in foo*.txt; do mv "$i" "OLD-$i"; done if it gets too long, copy/paste it into a file like ~/bin/renamer and multiple lines and indenting and make it a more permanent part of your colle…

Even better - in BASH and ZSH you can open up your preferred editor and compose a long command in that with "^x e" (or CTRL-x, e) - saving and closing will print the contents into your prompt, ready to be executed with an enter.

Re: Ask HN: How do I become a shell god?

#22
Two oreilly books to give you an overview, sorta know the lie of the land.

Classic Shell Scripting by Arnold Robbins

Unix Power Tools 3rd edition

Two additional worthwhile books:

The Unix Programming Environment by Kernighan and Pike

Mastering Regular Expressions by Friedl.

All 4 are classics.

Also try tldr.sh website in addition to man pages. They are easier to grok.

Re: Ask HN: How do I become a shell god?

#23

If you encounter a problem or task, then do it using shell commands. This will push into asking the question "what command can do X?" and "how do I connect command X to command Y?" and "how do loop commands over output?". Then just keep doing that over and over again. Learn the shell chainsaw: `xargs`. `xargs -L` vs `xargs` and `xargs -I` (examples will say use `{}` but I'm partial to `xargs -I @` because that works…

Can you explain or link further about the “chainsaw?” Google comes back with this post.

Re: Ask HN: How do I become a shell god?

#25
post #10

My way is: Try to write small loops and pipes on the command line. I do things like this all the time: for i in foo*.txt; do mv $i OLD-$i; done You'll find this breaks sometimes, so use control-r to recall the command and fix it for i in foo*.txt; do mv "$i" "OLD-$i"; done if it gets too long, copy/paste it into a file like ~/bin/renamer and multiple lines and indenting and make it a more permanent part of your colle…

Hi,

As of yours loop, such thing, when renaming files in bash, you can do `mv {,OLD-}foo*.txt`

Great practice would be to write report scripts which aggregate multiple data sources into single array of predefined objects which are finally sent into `stdout`, `/var/spool/user` or anywhere else.

Re: Ask HN: How do I become a shell god?

#28
By reading 1 dedicated shell book e.g. "Linux Command Line and Shell Scripting" you'll be at the top 10% of shell connoisseurs.

That said, I challenge the usefulness of deep shell knowledge.

If you're planning on writing 300 lines shell scripts, you're most likely doing it wrong, you should be using a full featured, modern programming language.

Re: Ask HN: How do I become a shell god?

#29
post #28

By reading 1 dedicated shell book e.g. "Linux Command Line and Shell Scripting" you'll be at the top 10% of shell connoisseurs. That said, I challenge the usefulness of deep shell knowledge. If you're planning on writing 300 lines shell scripts, you're most likely doing it wrong, you should be using a full featured, modern programming language.

That is uninspiring... is totally fine to have long shell scripts, and in itself, is no easier nor harder than any other language.

Worth noting that shell is a programing environment (not language) so is highly dependent on the tools you are using or gluing together to accomplish something.

Post reply on HN