Re: BASH and wildcard expansion

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

 



On Tue, 20 Aug 2013, Suvayu Ali wrote:

On Mon, Aug 19, 2013 at 05:18:40PM -0500, Bill Oliver wrote:

# Filename format YYYY_MM_DD--HHMM.zip
filename="$log_year-$log_month-$log_day--*.zip"

filelist=`ls $filename`

Please don't do this.  A much better solution is:

filelist=($log_year-$log_month-$log_day--*.zip)

See: <http://mywiki.wooledge.org/ParsingLs>



Thanks for the comment -- I hadn't thought of that.  However, it doesn't
work and it doesn't make sense to me.  I thought that putting things in
parentheses simply put it in a shell.

In any case, here's my test case.  I created two files:

2013-August-19--a.zip and
2013-August-19--ba.zip

Then, using this script:

******************
#!/bin/sh
# Date variables
log_year=`date "+%Y"`
log_month=`date "+%B"`
log_day=`date "+%d"`

# Filename format YYYY_MM_DD--HHMM.zip
filename="$log_year-$log_month-$log_day--*.zip"

filelist=`ls $filename`

echo $filelist
******************


I get the following output:

$ !./j
./jnk.sh
2013-August-19--a.zip 2013-August-19--ba.zip

Using this script:

******************

#!/bin/sh
# Date variables
log_year=`date "+%Y"`
log_month=`date "+%B"`
log_day=`date "+%d"`

# Filename format YYYY_MM_DD--HHMM.zip
filelist=($log_year-$log_month-$log_day--*.zip)


******************

I get:

$ ./jnk2.sh
2013-August-19--a.zip

For some reason, the second file (013-August-19--ba.zip) is not returned...

did you mean

filelist=$(ls log_year-$log_month-$log_day--*.zip)

?  ... but that puts the evil "ls" back in.  The complaint against "ls"
is that it breaks on wacky file names.  That isn't an issue here.


billo
--
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org




[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux