The Importance of Quotes In The Terminal


The Importance of Quotes In The Terminal

This week we check out single and double quotes in the Linux terminal.

Using quotes is pretty simple, but is a good thing to know. If you notice your expansion command going haywire, you can use quotes to suppress it. Type ls -l hak5 technolust.txt. You get an error. Using double quotes around the name of this text document will fix this error. Double quotes make any special characters inside the quotes lose their meaning except for ` (backtick), \ (backslash), and $. The suppressed ones are word splitting, pathname / tilde / brace expansion, but parameter / arithmetic expansion and command substitution still work. In our hak5 technolust example, the word splitting is still read, so we get that error. Now type ls -l "hak5 technolust.txt" and you get the correct output. From here we can mv "hak5 technolust.txt" to hak5_technolust.txt.

Try using single quotes for your arguments. Single quotes suppress the expansion even farther. For example: echo text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER, now add double quotes around text---USER, and try adding single quotes around it. After the break - how to suppress a character inside your quotes.

There is a way to suppress just one character inside your quotes. For example, since we know the $ will still expand in the output, we want to make sure it reads as just a $ during it's output. Type: echo "This costs $10.00". Now type: echo "This costs \$10.00". Keep in mind that the first 32 ASCII characters all do something different when proceeded by a \. By typing something like echo -e "Trust your technolust\a" or echo "Trust your technolust" $'\a' you'll get a bell alert on your computer.

Quoting is as necessary as anything in the shell, and it's incredibly useful. Make sure to email me with your thoughts. And be sure to check out our sister show, Hak5 for more great stuff just like this. I'll be there, reminding you to trust your technolust.