Again tcsh problems

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
DanielDD
Posts: 17
Joined: 2013-10-28T01:57:10-07:00
Authentication code: 6789

Again tcsh problems

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Again tcsh problems

Post 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
snibgo's IM pages: im.snibgo.com
DanielDD
Posts: 17
Joined: 2013-10-28T01:57:10-07:00
Authentication code: 6789

Re: Again tcsh problems

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Again tcsh problems

Post 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.
snibgo's IM pages: im.snibgo.com
DanielDD
Posts: 17
Joined: 2013-10-28T01:57:10-07:00
Authentication code: 6789

Re: Again tcsh problems

Post 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
DanielDD
Posts: 17
Joined: 2013-10-28T01:57:10-07:00
Authentication code: 6789

Re: Again tcsh problems

Post 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
DanielDD
Posts: 17
Joined: 2013-10-28T01:57:10-07:00
Authentication code: 6789

Re: Again tcsh problems

Post 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
Post Reply