Read: Bad Variable Name

B

Bastami

Guest
Hello all,
I am running the below shell script on my Ubuntu
Code:
while read *
do
awk 'NR==start,NR==end {sum+=$2} END {print FILENAME,start,end,sum}' start="$f2" end="$f3" "$f1"
done < B > B.new
and I 'm getting this error:
Code:
read: f100: bad variable name
f100 is one of many files in directory (f1, f2, ..., fn). When I change the name of f100 to 'hundred' the error will repeat for the next files (f101).
what is wrong with file names?
Any help would be greatly appreciated.
 


OP
W

WharfRat

Guest
You cannot use the * for a reply variable.. If you enter
Code:
echo *
in the terminal the shell expands the '*' to the names of the files in the current working directory before the echo command is executed, which is the same thing that's happening with read in your script.

read is for reading a single line from the standard input, or in other words accepting input from the user from the keyboard. If you don't supply a variable the line read is stored in the REPLY variable.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Staff online


Top