Page 1 of 1

Problem with unix subdirectory relative path as input file..

Posted: 2013-12-01T11:54:08-07:00
by perhapsyes
I have been having some trouble using relative paths as an option in a unix script which i'll call 'example.sh'.
contents of example.sh

Code: Select all

convert resize "$1" -resize 100x100 "$1"
When I execute

Code: Select all

sh example.sh "somedirectory/image.png"
it does not recognize the subdirectory (presumably because of the slash). I've tried a few different things, but it just doesn't seem to work when it's in a subdirectory. Does anyone know a way around this or to escape it properly? I'm using a linux distribution and a bash shell.

Re: Problem with unix subdirectory relative path as input fi

Posted: 2013-12-01T12:03:48-07:00
by fmw42
Are you sure that is the problem. What error messages do you get?

Try putting the full path to convert in your command and see if that works. Also try full paths to your script.

Relative paths should work. If not try full paths to your images. Be sure you have read write permissions.

Re: Problem with unix subdirectory relative path as input fi

Posted: 2013-12-02T06:33:53-07:00
by rich2005
Maybe pass two variables to the script.

Code: Select all

#!/bin/bash

# cdpath=/.
cd $1
convert "$2" -resize 100x100 new_"$2"
mv new_$2 ../$2
cdpath will set a base for the relative path then
sh example.sh "somedirectory" "image.png" should work (just the names, no slashes)
edit: as you have guessed, that cdpath is not required.


renamed the output image because it will overwrite the existing.
move and rename the resized file up one level to the directory the script is in.

Question in the op what does the first resize do? Throws up an error here.

using ImageMagick 6.8.0-2 and PClinuxOS