How to use quoting in unix & linux?
-
Quoting is used for circumstance where you are setting a variable or printing a string.
If i echo out a string with special characters like $1, you can see they do not get printed.
$ echo This is a $1 value This is a value
But if you use single quotes..
$ echo 'This is a $1 value' This is a $1 value
You cannot have single quotes with single quotes even with backslashes.
Now double quotes, ignore pipe characters, aliases, tilde substitution, wildcard expansion, process substitution, brace expansion, and splitting into words via delimiters. Single quotes inside double quotes have no effect.
Double quote allow for parameter substitution, command substitution, and arithmetic expression evaluation. You can include double quotes inside double quotes using backslash-escape character \
tropicalfruit=pineapple
Print the variable above with single quotes around it
$ echo \'$tropicalfruit\' 'pineapple'
© Lightnetics 2024