simple (and stupid) shell scripting question

Eray Aslan eray.aslan at caf.com.tr
Mon Feb 15 12:10:12 UTC 2010


On 15.02.2010 09:21, Nerius Landys wrote:
> But in the case where you're assigning the output of ls directly to a
> variable like this:
> 
> FOO=`ls`
> 
> vs
> 
> FOO="`ls`"
> 
> the text assigned to FOO is the same, right?

Apparently, it is:

sh-4.0$ touch "x *"
sh-4.0$ FOO=`ls`;echo "$FOO"|od
0000000 020170 005052
0000004
sh-4.0$ BAR="`ls`"; echo "$BAR"|od
0000000 020170 005052
0000004

There might be some corner cases tho.  Test before puting into
production (newlines/control chars in file names, different versions of
shell, different set/shopt options, changes in IFS etc).

-- 
Eray


More information about the freebsd-questions mailing list