Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

put variable in for loop pls ... 1

Status
Not open for further replies.

h3nd

Programmer
Jul 1, 2006
147
AU
Hi guys,

Here's part of my code
Code:
...
parameter="Current_Rates"

for f in `find . -name "*.csv" -maxdepth 1`
        do
        dir=`echo $f | sed 's/.*\(.\{8\}\).csv$/\1/'`
                if [[ $dir -lt $tdate ]];then
                                echo $parameter_$dir
                fi
        done

why the variable $parameter can not include in for loop ?
how do I put the variable $parameter into my for loop ?

Thanks guys,
 
Try this...
Code:
...
parameter="Current_Rates"

for f in `find . -name "*.csv" -maxdepth 1`
        do
        dir=`echo $f | sed 's/.*\(.\{8\}\).csv$/\1/'`
                if [[ $dir -lt $tdate ]];then
                                echo $[b]{[/b]parameter[b]}[/b]_$dir
                fi
        done
Add curly braces around the variable name.
 
The reason, the shell thought the underscore was part of the variable name and the variable "[tt]parameter_[/tt]" doesn't exist. The curly braces tell it exactly what the variable name is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top