Reputation: 10203
Consider the following C shell script:
set MYVAR = "a='str.*' -p -10"
set output = `echo "$MYVAR" | sed 's/-p -[0-9]\+/-p -100/g'`
echo "$output"
When sourced from the shell, I get the error echo: no match
. What changes can I make to the script to avoid the error? I tried adding ":q" and using a Perl one liner but haven't found an elegant solution.
Upvotes: 1
Views: 4959
Reputation: 339
This is tricky because you have both ".*" {which would glob for files} and a single quote in MYVAR {which means you can't use the ' to say interpret literally} The best I can think of here is to replace the double quote in MYVAR with single quotes in which case everything should work. Your sed line doesn't work. But that is not the problem. I replaced the sed to mimic what I think you are trying to do.
So:
- set MYVAR = 'a="str.*" -p -10'
- echo $MYVAR
echo: No match. #as expected because you need to put it in double quotes
- echo "$MYVAR"
a="str.*" -p -10
- set output = `echo "$MYVAR" | sed 's/-p -10/-p -100/g'`
- echo $output
echo: No match. #Reason same as before
- echo "$output"
a="str.*" -p -100
Upvotes: 2