-   Linux - General (
-   -   shell script: how to insert a command into quotes (

alekone 01-12-2009 09:08 AM

shell script: how to insert a command into quotes
I'm running this command

convert -format jpg "$i" "/Volumes/TESTHD/JPEG/$i.jpg"
(it's an imagemagick command)

the problem is, it produces files with double extension (.tif.jpg).
to avoid this, I'd like to use something like basename $i, but I don't know hot to put it inside the quotes.

i tried


convert -format jpg "$i" "/Volumes/TESTHD/JPEG/basename $i.jpg"
but obviously it doesn't work. help!

eco 01-12-2009 09:12 AM

Try something like this:


convert -format jpg "$i" "/Volumes/TESTHD/JPEG/`echo ${i}|cut -d. -f1`.jpg"
Hope this helps.

alekone 01-12-2009 09:19 AM

thank you! super-fast answer
I'll give it a try.

I (almost) understand what it does, but why do you need {}?

eco 01-12-2009 09:46 AM


Not so fast answer ;)

The '{}' is only to make sure the variable is clearly defined. Just something I tend to always do.

It avoids problems like


echo "$ibar"    # $ibar does not exist
echo "${i}bar"

alekone 01-12-2009 09:56 AM

got it!
I meant: thank you for your answer, you answered in a really short time in my opinion. ;)
sorry for my poor english.
thank you, again!

All times are GMT -5. The time now is 02:01 AM.