News for hackers. Stuff that matters.
Re:Ask HN: How can I get better at bash? by SEJeff on Monday June 26, 2017 @12:30PM (#14638014)
As silly as it sounds, when I was a new Unix SysAdmin, I read the entirety of "man 1 bash", which includes all bash builtins. I found that it improved by bash-foo 100x simply by knowing about so many of the utilities. I also took some cliff notes for things that seemed generally useful.

I did it for an hour or so a night for a week or so.

That being said, a few of my personal favorites to memorize:

* Parameter expansion: https://www.gnu.org/software/bash/manual/html_node/Shell-Par...

* All of test(1) as you can use them in any if statement (/usr/bin/[ is a real command!): https://linux.die.net/man/1/test

* Knowing most of the bash internal variables: http://tldp.org/LDP/abs/html/internalvariables.html

* Keyboard shortcuts and how they are useful. A few example: CTRL-l (no need to ever use /usr/bin/clear), CTRL-k, CTRL-u, CTRL-e, CTRL-a, CTRL-w, CTRL-arrow left, CTRL-arrow right, CTRL-r (history reverse search with find as you type autocomplete)

The best way you can learn the shell is by using Linux as your primary desktop for at least a few months. You'll get very proficient very quickly by doing that.

Re:Ask HN: How can I get better at bash? by _ncxu on Monday June 26, 2017 @02:29PM (#14639098)
Also CTRL-_ which is "undo whatever you just typed"
Re:Ask HN: How can I get better at bash? by SEJeff on Monday June 26, 2017 @02:38PM (#14639157)
That is a great one I didn't know (and I've been a 'nix monkey professionally since 2005). Thanks!
Re:Ask HN: How can I get better at bash? by 7171u on Tuesday June 27, 2017 @11:43PM (#14651550)
I was using CTRL+C to open new prompt instead of undoing. Thanks for this.
Re:Ask HN: How can I get better at bash? by amelius on Monday June 26, 2017 @02:59PM (#14639309)
Ok, but where is the "redo" option?
Re:Ask HN: How can I get better at bash? by Aardwolf on Monday June 26, 2017 @03:12PM (#14639408)
pressing CTRL-w a few times feels easier to me, less awkward key combination
Re:Ask HN: How can I get better at bash? by yebyen on Monday June 26, 2017 @03:55PM (#14639800)
CTRL-w just deletes a word at a time. CTRL-_ it appears doesn't just delete the whole line you just typed, it does undo of the thing you just typed... counting backspace as "one thing you just typed" -- so it does some things you can't achieve with CTRL+w, you can even get back some text that you just erased.

I never knew this shortcut before. (I will probably never use it...)

Re:Ask HN: How can I get better at bash? by vram22 on Monday June 26, 2017 @07:04PM (#14641165)
Some good advice there.

One thing I have found that less people seem to know, is that the Unix metacharacters are expanded by the shell (bash etc.) not by individual commands. What this implies is that any command, whether built-in or written by you (in C, bash, Python or any other language), has metacharacter support automatically. That is, things like the file globbing/wildcard characters like *, ?, and [ ranges ].

This was not originally true on DOS (as a counterexample) and not sure whether it is true on Windows today (haven't checked), though I did notice that more commands seem to support wildcards in Windows nowadays.

Also, for some years now, Windows too has had redirections like:

command >file.txt 2>&1

(redirect stderr (2) to the same destination that stdout (1) is pointing to, i.e. file.txt), which Unix had from the start.

Re:Ask HN: How can I get better at bash? by keithpeter on Monday June 26, 2017 @02:11PM (#14638968)

    keith@illy:~$ man bash | col -b | wc
       5738   46385  323374
A slim novella's worth on Debian Sid's man page. Never thought of just reading the whole thing, so thanks.
Re:Ask HN: How can I get better at bash? by mtdewcmu on Monday June 26, 2017 @01:40PM (#14638726)
Yes, the man page is very good. The online gnu documentation is good, too. Some of the information will not be categorized as bash.[1] Also check out sed and awk.

[1] http://www.gnu.org/software/coreutils/manual/html_node/index...

Re:Ask HN: How can I get better at bash? by vram22 on Monday June 26, 2017 @07:20PM (#14641242)
>All of test(1) as you can use them in any if statement (/usr/bin/[ is a real command!):

Yes, and not only in an if statement. You can also use test or [ command in commands of the form:

test condition && commmand2

or

test condition || command2

which will only work if the condition is true or false, respectively (IIRC, need to check this).

Re:Ask HN: How can I get better at bash? by SEJeff on Tuesday June 27, 2017 @11:28AM (#14646270)
That is correct, no need to check on this. I've done this for years :)
Re:Ask HN: How can I get better at bash? by vram22 on Tuesday June 27, 2017 @12:05PM (#14646655)
Thanks. Well, I was nearly 100% sure too (been using Unix for years too (from before Linux was created)), but "nearly" is not 100% (since I don't use that feature often), and don't like to make claims I am not sure about without a disclaimer, hence I made one :)
Re:Ask HN: How can I get better at bash? by lohengramm on Monday June 26, 2017 @01:13PM (#14638452)
+1 for the shortcuts.

Also one should take a look at rlwrap after becoming comfortable with the keyboard shortcuts.