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…
Ask HN: How do I become a shell god?
21–30 of 34 posts
Re: Ask HN: How do I become a shell god?
#22Classic 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?
#23If 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…
Re: Ask HN: How do I become a shell god?
#24Re: Ask HN: How do I become a shell god?
#25My 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…
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?
#26Re: Ask HN: How do I become a shell god?
#27Re: Ask HN: How do I become a shell god?
#28That 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?
#29By 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.
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.
Re: Ask HN: How do I become a shell god?
#30I’d suggest taking any task that you would do in excel, and do it on the command line.