Live data from Hacker News

Ask HN: How do I become a shell god?

news.ycombinator.com

1–10 of 34 posts

Ask HN: How do I become a shell god?

#1
It seems many things can be done with a one-liner or short shell script, but I'm not fluent enough to recognize those patterns yet. I do know a few basic commands, but much of *nix seems like a bag of undocumented tricks; and man pages are hieroglyphic IMO. Is there a cohesive path to learning all the tricks? All of them!

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

#4
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...

Those who don't know Awk do comical things with cockamamie combinations of cut, sed, grep, echo ... and clumsy loops written in shell.

Other than shell syntax and semantics, it's a matter of knowing a large number of utilities.

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

#5
Unix evolved in an age of batch processing.

Files were the default datastore, and text streams the default inter-process interface.

Although the world is changing, a surprising amount of it still operates through those tools.

A good way to understand the tooling is to do one of the Linux from scratch or similar projects, perhaps look at swapping out some tools for self-written alternatives, and scratching your own itch building projects that solve problems you have yourself.

Most people who reach a degree of proficiency in shell also have an innate understanding of the kernel's general organization, the nature of filesystems, the boot process, database types, are capable of programming in multiple languages, comoprehend network programming and the challenges of locking and distributed state, and so on. You can't learn all of it in one go, so just leverage that interest and enthusiasm and devote the time.

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

#6
Best is to identify the shell as a solution within your daily work. The maybe obvious step 1 is to switch to an unixoid OS such as Linux or Mac OS. Step 2 is to make the shell easily reachable, for example with buttons to open a shell in your current directory or with a drop-down terminal like http://guake-project.org/

Then, whenever you have some everyday problem (frequently some "batch" or "bulk" job operating on many files), consider using the shell instead some 3rd party tools.

If you really are into it, consider working with suitable files. For instance, drop office files (MSO or LibreOffice/OpenDocument) and instead switch to plain text files (Markdown or Latex). They are much easier to process in the command line. Also consider using git instead of dropbox and friends, because it is CLI-first. There is a universe waiting to be explored: There are CLI clients for almost everything (chatting, mail, web, etc.).

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

#8

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.

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

#9
Use it a lot and find ways to learn how it works:

- read the manual (see other posts) - customize it (and persevere) - make it fun

The second is really helpful. A lot of my shell commands/utilities [0] are simply better-for-me ergonomics on commonly available commands. These include things like `fzf` wrappers and more sophisticated aliases.

I specifically found the making of `fzf` based utilities to be a source of major learnings. It requires you to know quite a bit of shell mechanics to do things nicely. It's very similar to building a UI with APIs. You invariably learn the surrounding concepts (HTTP, auth for APIs, content types, caching, etc.)

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

#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 collection.

Also, shell isn't the end. I move to python when shell scripts get cumbersome. python can easily parse arguments (argparse), handle filenames with weird characters in them (os.path), walk trees of files (os.walk) and more.

Post reply on HN