How do I expand variables in a bash variable without expanding wildcard?
bash, eval
Solution
Turn off globbing in bash, then reenable it.
set -f
var="$FOO/bar/baz*"
set +f
Problem
I have a variable that contains this kind of string : ``` var='$FOO/bar/baz*' ``` and I want to replace the variable $FOO by its content. However, when i do ``` var=$(eval "echo $var") ``` The variable is replaced, but the star is also replaced so that `var` now contains every possible match in my filesystem (as if i pressed tab in a shell). for example, if $FOO contains /home, `var` will contain `"/home/bar/baz1.sh /home/bar/baz2.sh /home/bar/baz.conf"` How do i replace the variable without expanding wildcards ?