Created
August 11, 2013 21:26
-
-
Save orbekk/6206917 to your computer and use it in GitHub Desktop.
Bash quoting example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function my_print() { | |
for arg in "$@"; do | |
echo -n "{$arg} " | |
done | |
echo | |
} | |
var1="Two bits" | |
# Print var1 as one string. | |
my_print "\$var1 = $var1" | |
# Output: {$var1 = Two bits}. | |
# "Double quoting is actually 'unquoting'". "\var1 =" is inside quotes, $var is outside | |
# of the quotes, and the "" is an empty string at the end. | |
# | |
# Therefore this gets interpreted as the two strings "\$var1 = Two" and "bits". | |
my_print "\$var1 = "$var1"" | |
# Output: {$var1 = Two} {bits} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment