Live data from Hacker News

Ask HN: How do I become a shell god?

news.ycombinator.com

11–20 of 34 posts

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

#11
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 with Fish and Bash, plus it's a single character.

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

#14

Read the whole POSIX specification for the "Shell Command Language", and in particular how input is processed by the shell through all the multiple expansion passes. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V... From there, you have a better background for reading the documentation of shell implementations, like Bash. Also study Awk: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/a... Th…

I find Perl to be good for these things.

That is, or was, Perl's purpose, right? Process pipelines of text data but in a more structured way?

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

#19

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…

I enjoy intentionally avoiding some uses of the chainsaw by instead piping into "while read -r", and hence getting a loop body with some room to manoeuvre.

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

#20
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…

I'm often hesitant to run stuff like this because there's a non-zero chance you'll lose important data or bork your OS install with a bad command or typo. I've considered writing an alias that dockerizes my current directory and opens a shell in the new container to test risky commands. Like a localhost staging environment.
Post reply on HN