![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| what is wrong with this tr -d? | cleansing_flame | UNIX for Dummies Questions & Answers | 3 | 02-06-2008 09:34 AM |
| What’s wrong with the following? | vrn | UNIX for Dummies Questions & Answers | 8 | 03-19-2006 06:09 PM |
| where have i gone wrong? | Blip | Shell Programming and Scripting | 3 | 01-28-2004 01:43 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
what is wrong here
Hello,
I have a simple script such as ----------------------------- #! /bin/sh YEAR=`date -u +%Y`; MONTH=`date -u +%m`; DAY=`date -u +%d`; DATE=$MONTH$DAY$YEAR LOGFILES=auditTrail-$DATE LOGMATCH=$LOGFILES\* ARGUM='' # find all files and write them to a file find . -name "$LOGMATCH" > temp cat ./temp | while read file_line do ARGUM=$file_line' '$ARGUM echo $ARGUM done echo "final string contains" echo $ARGUM echo "nothing" ---------------------------- I was hoping that it will read a line one at the time and add to the variable ARGUM. It does exactly that within the loop. Yet, when it gets out the loop, last line echo $ARGUM return nothing output looks like this ./log/auditTrail-02022007.10.out ./log/auditTrail-02022007.14.out ./log/auditTrail-02022007.10.out ./log/auditTrail-02022007.7.out ./log/auditTrail-02022007.14.out ./log/auditTrail-02022007.10.out ./log/auditTrail-02022007.1.out ./log/auditTrail-02022007.7.out ./log/auditTrail-02022007.14.out ./log/auditTrail-02022007.10.out final string contains nothing ----------------------- I thought that variable ARGUM is global everywhere in the script. What am I missing? Thank you in advance |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
The while runs in a subshell.
So all changes made to ARGUM are gone when the loop is done When you change it into" while read file_line do ARGUM=$file_line' '$ARGUM echo $ARGUM done < cat ./temp it will work fine Typical behavior for Linux systems or the bash shell. |
|
#3
|
|||
|
|||
|
Thank you for the reply.
I tried, but now am getting syntax error: `./temp' unexpected Last edited by arushunter; 02-02-2007 at 04:20 PM. |
|
#4
|
||||
|
||||
|
remove the cat.
|
|
#5
|
|||
|
|||
|
Indeed, the "cat" shouldn't be there, I copied/pasted a little too fast
|
|
#6
|
|||
|
|||
|
thank you again. I did remove "cat"
and my while loop look as while read file_line do ARGUM=$file_line' '$ARGUM done < ./temp echo $ARGUM Yet, I am still getting emty output. echo @ARGUM produces empty string. Any other suggestings. Thank you in advance |
|
#7
|
||||
|
||||
|
Switch ksh or bash. They won't do that to while loops.
|
||||
| Google The UNIX and Linux Forums |