Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Bash / Shell Scripting (http://www.programmingforums.org/forum26.html)
-   -   Filename expansion problems in script (http://www.programmingforums.org/showthread.php?t=3374)

msalowit Apr 15th, 2005 9:39 AM

(Fixed) Filename expansion problems in script
 
I'm having a problem with figuring out how to do filename expansion in a script in such a manner as it behaves on the command line. If I run command lines options as follows:

cat /<path>/old/{2005.04.05,2005.04.08}/*.log

I get output as expected.

When I try and drop it into a script as follows:

#!/bin/bash

cd log

function cat_archive_sec_logs ()
{
cat old/{$logdates}/gs_*_security.log
}

function ie_parse_all_sec_filter ()
{
cut -f 2,3,6- -d " " | \
sed -f /usr/local/bin/seclogsed -f /tmp/ul-playersed-short | \
egrep -i "$var" | \
sort -t " " -k 1,2
}

ls old
echo "Please select log date. Example 2005.04.05 :"
read logdates junk
echo "Playernames seperated by pipes. Example: joe|john|julie :"
read var junk
cat_archive_sec_logs | ie_parse_all_sec_filter "$var"

and give it input as 2005.04.05,2005.04.08 it aborts:

cat: <path>/old/{2005.04.05,2005.04.08}/gs_*_security.log: No such file or directory

It appears to be treating the {} as literals and NOT doing expansion on the values contained thereiin.

I -can- do 2005.04.0[5,8] and it would behave as expected, but trying to explain a more complicated date search to non-technical people is an excercise in futility, I want to be able to tell them to paste the datelisted folders just like the command-line example.

I have tried various combinations of declarations, quoted, unquoted, ${logdates} {${logdates}} and even escaped the braces, none of it seems to work.

All the rest of the script works as expected, and I can do single date-directories fine.

Any help appreciated.

A suitable test script:

#!/bin/bash

cd /

function dirlist ()
{
ls /$logdates/
}

ls /
echo "Please select dir. Example opt,etc :"
read logdates junk
dirlist

And to make things more exascerbating, declaring the directories explicitly instead of using a variable inside the script works just peachy:

ls /{opt,etc}/

give the expected output.

Thanks in advance,

Mark

msalowit Apr 15th, 2005 10:21 AM

Okay, I figure it out. That is to say, I gave up and did it this way:

for logdate in $logdates
do
ls $logdate
done

and removed the junk arg so spaces were allowed.

If the hammer you have isn't big enough, change hammers.

Mark


All times are GMT -5. The time now is 2:10 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC