Stripped argument

Hi there

Has anyone seen this behaviour before, and if so, do they know why this happens? I am running this in BASH:

$ export DEV="/usr/sbin/diskutil list | /usr/bin/grep Master | /usr/bin/awk '{ print $6 }'"
$ echo $DEV
/usr/sbin/diskutil list | /usr/bin/grep Master | /usr/bin/awk '{ print }'

If you notice, the $6 argument has been stripped from the echo'd output.

Mike

That's because the shell treat $6 as a commandline variable - it doesn't see the awk block and know it's an awk command:

$ export DEV="/usr/sbin/diskutil list | /usr/bin/grep Master | /usr/bin/awk '{ print \$6 }'"

FWIW - what you want here is probably an alias unless you plan to :

eval $DEV

The value of the variable EXP is specified between ", so the shell interprets the value before affectation.
$6 is replaced by the value of argument 6 which seems to be be not set in your case.

Protect $6 with \ to avoid substitution:

export DEV="/usr/sbin/diskutil list | /usr/bin/grep Master | /usr/bin/awk '{ print \$6 }'"

or use simple quotes ', in that case internals simple quotes must be protected :

export DEV='/usr/sbin/diskutil list | /usr/bin/grep Master | /usr/bin/awk \'{ print $6 }\''

Jean-Pierre.

mikie

I think its trying to expand the variable and since that variable is not intialized it is
replacing it with a BLANK.
see below

dam@athena:~$ echo '{ print $6 }'
{ print $6 }
dam@athena:~$ echo "'{ print $6 }'"
'{ print }'

not sure what the workaround is.

Ahh, that explains it very well. Thank you both, Jim and Jean-Pierre.

Mike