I'm a Sr. Software Engineer at Flashpoint. I specialize in Python and Go, building functional, practical, and maintainable web systems leveraging Kubernetes and the cloud. Blog opinions are my own.
Hi there! I found the man pages dense and opaque at times, which is why I put this article together. Are there any especially dangerous practices that you’d like to point out?
It's true that bash man page is a very dry reading, but once you get the basics figured out, it is definitely the best source. That's why it's important to use the correct terminology in your article - it will allow people to quickly find the necessary subjects in the man page.
Now, for the mistakes in the article.
"(( Double Parentheses ))" is actually a compound command that undergoes arithmetic evaluation. its the equivalent of "let".
# Not correcta=(( 4 + 1 ))# Correct((a=4 + 1))
"$( Dollar Single Parentheses )" is actually called "Command substition"
"$( Dollar Single Parentheses Dollar Q )$?" is an absoultely HORRIBLE trick, NEVER EVER EVER do this! Oh, and btw, this doesn't actually work, because, the few times that it won't spew out an error, it will always evaluate to true.
# This is very badif[[$(grep-q PATTERN FILE )$?]];then
...
# Do this insteadif grep-q PATTERN FILE;then
...
# oh, and by the way[[$(false)$?]];echo$?#=> 0# thats because $? is evaluated as a string, and "1" is non empty[[$(false)$?]];echo$?#=> bash: conditional binary operator expected#=> bash: syntax error near `$?'# LOL
"$(( Dollar Double Parentheses ))" is actually called "Arithmetic expansion" with the expression within undergoing "Arithmetic evaluation". An interesting fact: double paratheses is not the only place arithmetic evaluation occurs: it also occurs inside array subscripts, which can be a pretty surprising thing sometimes.
[ Single Square Brackets ]. This deserves a special caution: unless you require backward compatibility with classic sh, you should NEVER use it. It's error-prone, requires gillion of quotes to make reliable and spawns a separate process for no good reason. Also, "[[" has more features.
"{ Single Curly Braces }" is called "brace expansion".
"${dollar braces}" is called "parameter expansion".
I'm a Sr. Software Engineer at Flashpoint. I specialize in Python and Go, building functional, practical, and maintainable web systems leveraging Kubernetes and the cloud. Blog opinions are my own.
Yep, I’m aware of what these are all called. I wrote it this way because the target audience most likely wouldn’t, and I wanted to make it an accessible visual guide. That being said, your other notes are helpful, and, when I get a chance, I’ll do my best to add the warnings and caveats where they’re needed. Thanks for taking the time to walk me through your experiences!
Agreed with him. The Bash Reference Manual is actually a 'reference' not meant to be read directly, but provides all the details. Tutorial authors should give the corresponding terminology for each trick. I've collected all the corresponding terminology here for quick reference to man bash. Just search for the terminology (remember to capital the first letter so that smart cases are matched) in the manual page and there will be a lot more details.
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi there! I found the man pages dense and opaque at times, which is why I put this article together. Are there any especially dangerous practices that you’d like to point out?
It's true that bash man page is a very dry reading, but once you get the basics figured out, it is definitely the best source. That's why it's important to use the correct terminology in your article - it will allow people to quickly find the necessary subjects in the man page.
Now, for the mistakes in the article.
"$( Dollar Single Parentheses )" is actually called "Command substition"
"$( Dollar Single Parentheses Dollar Q )$?" is an absoultely HORRIBLE trick, NEVER EVER EVER do this! Oh, and btw, this doesn't actually work, because, the few times that it won't spew out an error, it will always evaluate to true.
"$(( Dollar Double Parentheses ))" is actually called "Arithmetic expansion" with the expression within undergoing "Arithmetic evaluation". An interesting fact: double paratheses is not the only place arithmetic evaluation occurs: it also occurs inside array subscripts, which can be a pretty surprising thing sometimes.
[ Single Square Brackets ]. This deserves a special caution: unless you require backward compatibility with classic sh, you should NEVER use it. It's error-prone, requires gillion of quotes to make reliable and spawns a separate process for no good reason. Also, "[[" has more features.
"{ Single Curly Braces }" is called "brace expansion".
"${dollar braces}" is called "parameter expansion".
Yep, I’m aware of what these are all called. I wrote it this way because the target audience most likely wouldn’t, and I wanted to make it an accessible visual guide. That being said, your other notes are helpful, and, when I get a chance, I’ll do my best to add the warnings and caveats where they’re needed. Thanks for taking the time to walk me through your experiences!
Agreed with him. The Bash Reference Manual is actually a 'reference' not meant to be read directly, but provides all the details. Tutorial authors should give the corresponding terminology for each trick. I've collected all the corresponding terminology here for quick reference to
man bash. Just search for the terminology (remember to capital the first letter so that smart cases are matched) in the manual page and there will be a lot more details.