Page 1 of 1

Again tcsh problems

Posted: 2018-08-28T15:24:43-07:00
by DanielDD
Hallo,

I created a minimal example:

Code: Select all

#!/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
The script produces error messages:

Code: Select all

-pointsize 80 -draw " gravity NorthWest fill black text 0,12 a "
convert: unable to open image `gravity': No such file or directory @ error/blob.c/OpenBlob/2705.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/504.
convert: unable to open image `NorthWest': No such file or directory @ error/blob.c/OpenBlob/2705.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/504.
....
However,

Code: Select all

convert a.tif -pointsize 80 -draw " gravity NorthWest fill black text 0,12 a " b.tif
works perfectly (I used copy and paste to get the value from namestr to the command line).

Any idea to get the script working.

Best regards,
Daniel

Re: Again tcsh problems

Posted: 2018-08-28T16:08:44-07:00
by snibgo
Variable expansion occurs after the command has been split into words (which is when the quotes have an effect). I suggest you write it like this:

Code: Select all

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

Re: Again tcsh problems

Posted: 2018-08-29T13:04:45-07:00
by DanielDD
@snibgo

This is quite correct, but it does not solve my problem.

I gave a minimal example. In some cases, $namestr is empty, and then,
your code leads to the execution:

Code: Select all

convert a.tif  "" b.tif 
which does not work. The quote-symbols " should be part of the string.

Best regards,
Daniel

Re: Again tcsh problems

Posted: 2018-08-29T13:47:40-07:00
by snibgo
You want the shell to act on the quotes. As far as I know, *nix shells interpret quotes before expanding variables, so a quote within the variable value won't do what you want.

(Windows shells work differently, and can do what you want.)

The problem is with shell scripting, not IM. I suggest you ask in a shell scripting forum.

Re: Again tcsh problems

Posted: 2018-08-29T14:57:23-07:00
by DanielDD
snibgo wrote: 2018-08-29T13:47:40-07:00 The problem is with shell scripting, not IM. I suggest you ask in a shell scripting forum.
Yes, you are right.

Daniel

Re: Again tcsh problems

Posted: 2018-08-30T06:15:41-07:00
by DanielDD
@snibgo

I found a clumsy solution:

If namestr is empty, I leave namestr1 = "-pointsize 80 -draw" and let
namestr2 empty. Then, your code leads to the execution:

Code: Select all

convert a.tif -pointsize 80 -draw " " b.tif
which works perfectly.

Daniel

Re: Again tcsh problems

Posted: 2018-08-30T11:26:06-07:00
by DanielDD
A solution is here:
https://www.unix.com/shell-programming- ... iable.html

One has simply to change the last line in my very first code to

Code: Select all

eval convert a.tif $namestr b.tif
Daniel