Skip to content

Instantly share code, notes, and snippets.

@orbekk
Created August 11, 2013 21:26
Show Gist options
  • Save orbekk/6206917 to your computer and use it in GitHub Desktop.
Save orbekk/6206917 to your computer and use it in GitHub Desktop.
Bash quoting example
#!/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