Page 2 of 2

Re: Trouble with quotes in BASH scripts

Posted: 2012-04-18T22:25:11-07:00
by anthony
A shell script only needs 'execute permission' if it starts with the UNIX #! syntax
You can add execute permission using

Code: Select all

   chmod a+x script_filename
But even if it does not have the execute permission, OR a #! magic at the start, you can still execute it as a script. You just have to tell the system what parser to use..

For example

Code: Select all

    sh script_filename
or

Code: Select all

   bash script_filename
Note the #! prefix at the start of the script is a special method to tell the 'kernel' what parser the the script uses. For shell scripts this is typically

Code: Select all

   #!/bin/sh
But for non-shell parsers (such as perl) another method (more of a trick) is typically used

Code: Select all

   #!/usr/bin/env perl
The "env" command will look for the "perl" parser anywhere on your command path and execute it. That means you do not have to hardcode its location in the #! line. "env" is common on all UNIX systems, and is often used for this purpose.

This will be imporant as the NEW IMv7 command ("convert" replacement) called "magick" can read options from a script, and such scripts are normally setup using magick of the form...

Code: Select all

    #!/usr/bin/magick -script
    # ...

For more information see my notes about "SheBang" as it is called here
http://www.ict.griffith.edu.au/anthony/ ... hebang.txt

Re: Trouble with quotes in BASH scripts

Posted: 2012-04-19T18:13:53-07:00
by AusS2000
fmw42 wrote:My suggestion is to make a test script with hard coded values and see if that runs. First test in the command line and then put it into your scripting environment with the right exec call.
Ok, here is my code, copy and pasted from the terminal:

/opt/local/bin/convert -size 320x85 canvas:none -font Helvetica -pointsize 72 -draw "text 25,60 'It works'" -channel RGBA -blur 0x6 -fill darkred -stroke magenta -draw "text 20,55 'It works'" /Library/Server/Web/Data/Sites/\~isellit/IMcaptcha/images/captcha.jpg

Creates a file as specified.

I them make a bash script:

#!/bin/sh
/opt/local/bin/convert -size 320x85 canvas:none -font Helvetica -pointsize 72 -draw "text 25,60 'It works'" -channel RGBA -blur 0x6 -fill darkred -stroke magenta -draw "text 20,55 'It works'" /Library/Server/Web/Data/Sites/\~isellit/IMcaptcha/images/captcha.jpg

Save it as cmdIW.sh and call it from the terminal:

bash /Library/Server/Web/Data/Sites/~isellit/IMcaptcha/cmdIW.sh

Creates file as specified.

I then call the script from the web browser via my Terascipt:
Command Line [Windows and UNIX]
/Library/Server/Web/Data/Sites/~isellit/IMcaptcha/cmdIW.sh

Works as specified.

Now to try to send some parameters to it.

Re: Trouble with quotes in BASH scripts

Posted: 2012-04-19T18:23:00-07:00
by anthony
If you can break up the line to basic image processing steps on each line.
It just makes it easier to read and understand.

See IM examples for hundreds of examples of this.

Re: Trouble with quotes in BASH scripts

Posted: 2012-04-19T18:24:58-07:00
by AusS2000
Hmm, it now seems to be working.

I have the bash script with $txtstr arguments in it and I'm calling it from terascript and passing those arguments. I'll play around some more and see if I can work out where I was going wrong before and will report back here and Terascript talk list.

Thanks for all your help.

Re: Trouble with quotes in BASH scripts

Posted: 2012-04-19T18:26:48-07:00
by AusS2000
anthony wrote:If you can break up the line to basic image processing steps on each line.
It just makes it easier to read and understand.
Unfortunately this was one of the things that I suspect was causing issues. Neither the \ nor the ^ seem to be recognised as line breaks and it would only execute the first line. I will play around some more and see if I can't sort this issue.

Re: Trouble with quotes in BASH scripts

Posted: 2012-04-19T18:38:57-07:00
by AusS2000
And again, it all seems to be working now:
  • #!/bin/sh
    /opt/local/bin/convert -size 290x70 xc:white -bordercolor blue -border 5 -fill black -stroke black -strokewidth 1 -font Helvetica -pointsize 40 \
    -draw "translate -120,0 skewX 0 gravity center text 0,0 '$txtstr1'" \
    -draw "translate -72,0 skewX 0 gravity center text 0,0 '$txtstr2'" \
    -draw "translate -24,20 skewX 0 gravity center text 0,0 '$txtstr3'" \
    -draw "translate 24,0 skewX 0 gravity center text 0,0 '$txtstr4'" \
    -draw "translate 72,40 skewX 0 gravity center text 0,0 '$txtstr5'" \
    -draw "translate 120,0 skewX 0 gravity center text 0,0 '$txtstr6'" \
    -fill none -strokewidth 2 -draw "bezier 0,80 100,20 200,60 300,0" \
    -draw "polyline 0,0 130,30 300,80" \
    /Library/Server/Web/Data/Sites/\~isellit/IMcaptcha/images/captcha.jpg