Reputation: 485
I have this script
$AIRLINECODE=xx
for i in $AIRLINECODE_response_*; do
echo $i
done
prints all the files in the directory even if they have a completely different name..
what can i do to limit the for to find only the files that have the wished pattern?
Upvotes: 0
Views: 66
Reputation: 289505
This is because of how you are using the variable name.
When you use $AIRLINECODE_response_
, bash interprets it as AIRLINECODE_response_
being the name of the variable. To make it work, use curly braces to specify what is the name: {AIRLINECODE}_response_
.
All together:
AIRLINECODE=xx
for i in ${AIRLINECODE}_response_*; do
echo "$i"
done
Also, note that you need to set the variable with AIRLINECODE=xx
. It is wrong to use $AIRLINECODE=xx
, because the variables are being set without the leading $
.
Upvotes: 2