[clue] shell scripting Q

Dan Kulinski daniel at kulinski.net
Mon Feb 11 17:24:50 MST 2013


Oh and thanks for explaining the reasoning behind the curly braces, that
can be important in such a situation as you explained.  I often use it
because I may do a statement such as:

for i in `ls *`; do filename=$( echo $i | sed -ie 's/\.*//'); convert $i
-geometry 600x480 JPG:${filename}-thumb.jpg; done

So if you need to have the output of your variable immediately followed by
some other string it is important to surround it with the curly braces.

I am sure there are other methods that are a bit easier than what I have
done there.

Dan




On Mon, Feb 11, 2013 at 5:03 PM, Dan Kulinski <daniel at kulinski.net> wrote:

> Marcus,
>
> I rushed my explanation and missed something.  You are quite right you
> can't force expansion in single quotes.  What you do is something like the
> following:
> var="'scale=2;${total}/60'"; echo $var | bc
>
> Dan
>
>
> On Mon, Feb 11, 2013 at 5:00 PM, marcus hall <marcus at tuells.org> wrote:
>
>> On Mon, Feb 11, 2013 at 03:27:08PM -0700, Dan Kulinski wrote:
>> > When you use single quotes you stop variable expansion.  Try double
>> quotes
>> > or forcing expansion with scale='2;${total}/60'
>> >
>> > Dan
>>
>> Double quotes is definately the answer..  But, I don't understand what
>> you're trying to say about "forcing expansion".
>>
>> Try the following:
>>
>> xxx=test
>>
>> echo $xxx
>> echo "$xxx"
>> echo '$xxx'
>> echo ${xxx}
>> echo "${xxx}"
>> echo '${xxx}'
>>
>> I think you will find that the single quotes never perform variable
>> substitutuion.  Where the curly braces are useful are when the variable
>> is immediately followed by a character that could be part of a variable
>> name.  For example:
>>
>> echo $xxx_yyy
>> echo ${xxx}_yyy
>>
>> The first case tries to expand the variable xxx_yyy, while the second case
>> expands the variable xxx and follows that expansion with "_yyy".
>>  Sometimes
>> it is very important, but usually it is not needed.
>>
>> marcus hall
>> marcus at tuells.org
>> _______________________________________________
>> clue mailing list: clue at cluedenver.org
>> For information, account preferences, or to unsubscribe see:
>> http://cluedenver.org/mailman/listinfo/clue
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cluedenver.org/pipermail/clue/attachments/20130211/371c1742/attachment-0001.html 


More information about the clue mailing list