Really quick here, how to jam arround with file names for handy output file name creation. When I make a thumbnail or do some kinds of conversion… many times I want to have the output file name sort of “based on” the input file name. A really good way to have that happen is with the variable expansion built into bash.

this is an example that would change the file extension:

infile=jonny.jpg
# starting match string with % mean must match end,
# starting with # mean must match front
imagemagic -i $infile -o ${infile/%.jpg/.gif}

there are a bunch of examples bellow in my notes for a presentation i gave at the olug on bash.

My notes from the talk on bash:
$ MYVAR=foodforthought.jpg
$ echo ${MYVAR##*fo}
rthought.jpg
$ echo ${MYVAR#*fo}
odforthought.jpg

$ MYFOO="chickensoup.tar.gz"
$ echo ${MYFOO%%.*}
chickensoup
$ echo ${MYFOO%.*}
chickensoup.tar

$ EXCLAIM=cowabunga
$ echo ${EXCLAIM:0:3}
cow
$ echo ${EXCLAIM:3:7}
abunga

# infile
infile=jonny.jpg
# starting match string with % mean must match end, starting with # mean must match front
imagemagic -i $infile -o ${infile/%.jpg/.gif}

Comments are closed.