I would like to concatenate strings together to create a command string in a csh script,file1.csh. However, csh keeps complaining errors for commandString variable and I do not really know what I did wrong. Here are part of codes.
set var1 = "Hat"
set var2 = 100
set embeddedString = 's/'$var1' =.*$/'$var1' = '$var2'/g'
set commandString = "sed -i ' "$embeddedString" ' productPrice.txt"
echo $commandString
My goal is to set commandString vairable to be something as
sed -i 's/Hat =.*$ /Hat = 100/g' productPrice.txt
Then, this commandString will be inserted into another script file,file2.csh. file2.csh is the actual script file which performs the substitution command for Hat's price. In addition, the values of var1 and var2 are read from a priceUpdateList.txt file so they are not fixed values. On other words, I can not simply type Hat and 100 in the commandString variable. Does anyone know how to use quotation correctly to generate the command string in csh ?
Thank you so very much,
You'll have to quote (at least 1x) the embedded single-quotes (i.e.
cmdStr = "sed -i \' ....
To actually run the $cmdStr you're going to needeval
right?To use shell debugging in csh (which I would recommend to see what is happening), change the first line in your script to
This will show you each line or block of code as it is executed, and then the same block of code with the environment variables expanded.