In Bash, when I do:
foo="*" echo $foo
* to the contents of the current folder. How do I make sure it just prints a literal
The same, by the way, happens with a regular
echo "$foo", it prints the contents of the current folder.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
Let us define
Now, try echo without quotes:
$ echo $foo File1 File2
The replacement of
* with a list of filenames is called pathname expansion. It can be suppressed with with double-quotes:
$ echo "$foo" *
In addition, double-quotes will prevent brace expansion, tilde expansion, and word splitting.
For completeness, try echo with single quotes:
$ echo '$foo' $foo
Single quotes prevent the shell from making any substitutions at all.