LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   shell script: how to insert a command into quotes (http://www.linuxquestions.org/questions/linux-general-1/shell-script-how-to-insert-a-command-into-quotes-696721/)

alekone 01-12-2009 09:08 AM

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

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

Code:

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:

Code:

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

Hi,

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

Code:

#!/bin/bash
i="foo"
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 12:29 AM.