Tcsh, using " in a string variable

Hallo,

I try to write a tcsh-script which works with ImageMagick.
The following command line works perfectly:

convert a.tif -pointsize 80 -draw " gravity NorthWest fill black text 0,12 a " b.tif

I use the following code in a script (it is a minimal example to show the problem):

#!/bin/tcsh 
set gf = \" 
set namestr = "-pointsize 80 -draw $gf gravity NorthWest fill black text 0,12 a $gf" 
echo $namestr
convert a.tif $namestr b.tif

In my opinion, the last line of the code should do the same as the above command. However, the last line produces error messages, which are related to the "-symbols in namestr.

Any idea to get the script working?

Daniel

Quotes inside quotes don't work that way. Once they're in a string, they're literal characters. This is to prevent chaos and unintended results whenever your input contains ".

What problem are you trying to solve with quotes-in-quotes? Argument splitting?

You can try another run of the shell parser (after the variable substituition)

eval convert a.tif $namestr b.tif

The second run should see the two " and form a "string".

The script works like this:

mv $file t.tif
if condition1 then
      convert t.tif stuff1 s.tif
      mv s.tif t.tif
endif
 
if condition2 then 
      convert t.tif stuff2 s.tif
      mv s.tif t.tif
endif

if condition3 then 
      convert t.tif stuff3 s.tif
      mv s.tif t.tif
endif

I want to prevent the generation of the temporary files s.tif to optimize the script.

if condition1 then 
    set s1 = stuff1
else 
    set s1 = ""
endif

# ... same for 2 and 3, and then

convert $file $s1 $s2 $s3 t.tif
 

Daniel

------ Post updated at 12:07 PM ------

It worked, thanks!!!