Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 15th, 2005, 9:39 AM   #1
msalowit
Newbie
 
Join Date: Apr 2005
Posts: 2
Rep Power: 0 msalowit is on a distinguished road
(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

Last edited by msalowit; Apr 15th, 2005 at 10:21 AM.
msalowit is offline   Reply With Quote
Old Apr 15th, 2005, 10:21 AM   #2
msalowit
Newbie
 
Join Date: Apr 2005
Posts: 2
Rep Power: 0 msalowit is on a distinguished road
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
msalowit is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:14 AM.

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