bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: what is wrong here?


From: mhenn
Subject: Re: what is wrong here?
Date: Wed, 28 Mar 2012 18:25:25 -0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11

Am 08.08.2011 15:22, schrieb Francky Leyn:
> On 8/8/2011 2:17 PM, mhenn wrote:
>> Am 08.08.2011 11:33, schrieb Francky Leyn:
>>> Hello,
>>>
>>> consider the following code:
>>>
>>> EXTENSION=jpg
>>> INPUT_FILES=*.$EXTENSION
>>
>> echo "$INPUT_FILES" #obviously wrong
>> #instead maybe
>> INPUT_FILES="$(ls *.$EXTENSION)"
> 
> I tried something similar:
> 
> INPUT_FILES=`ls *.$EXTENSION`
> 
> This worked when there were files.
> But when there were no matching files, it didn't.
> In that case the words of the ls error message were
> considered as files, which is obviously wrong.
> 
> I'm new to bash, and have never seen a construct like yours.
> Could you briefly explain what the dollar and the () mean (subshell)?

`<stuff>` also creates a subshell :)
and $(<stuff>) actually does the same. See
        man bash | less -p '\$\(command'

> 
> Btw: how can I get rid off the ls error message in your construct?
> I tried already by postponing with >/dev/null, and 2>/dev/null, but
> that all doesn't help. Is ls writting to /dev/tty? and in that case,
> how can I suppress the ls error message?

INPUT_FILES="$(ls *.$EXTENSION 2>/dev/null)"
if [ -z "$INPUT_FILES" ]; then echo "no such file"; fi

> 
> Anyway, your construct works fine for files without spaces or newlines.
> Now up to the link you have me.
> 
> Thanks for the help!

np



reply via email to

[Prev in Thread] Current Thread [Next in Thread]