Consider the following:
#!/bin/tcsh
set thing = 'marker:echo "quoted argument"'
set a = `echo "$thing" | sed 's/\([^:]*\):\(.*\)/\1/'`
set b = `echo "$thing" | sed 's/\([^:]*\):\(.*\)/\2/'`
echo $a
echo $b
$b
echo "quoted argument"
This gives
marker
echo "quoted argument"
"quoted argument"
quoted argument
If $b
is echo "quoted argument"
, why does evaluating $b
give a different result from echo "quoted argument"
?
Since I know tcsh
is awful (but it's what I have to use for work), here is the same problem in Bash:
thing='marker:echo "quoted argument"'
a=`echo "$thing" | sed 's/\(.*\):\([^:]*\)/\1/'`
b=`echo "$thing" | sed 's/\(.*\):\([^:]*\)/\2/'`
echo $a
echo $b
$b
echo "quoted argument"
The output is the same. Note that, were I doing this in Bash, I would certainly use a map. I do not have that luxury :)
. The solution must work in tcsh
.
Desired Output
I would like $b
to behave just as if I typed the command in myself as I see it:
marker
echo "quoted argument"
quoted argument
quoted argument
This is a follow-up question to Accessing array elements with spaces in TCSH.
"quoted argument"
, then you have to escape them so the shell does not consume them OR put extra quoting values in your initial string to begin with.' ....'\"'....'
might work, or you might need up to 5 '\\' chars to protect your dbl-qt from being stripped by shell procing. – Baskinecho "quoted argument"
to appear. While considered evil by many, considering your constrained use, try setthing = 'marker:eval echo "quoted argument"'
. (Using eval). I can't test this in my environment. Good luck. – Baskin