Not sure why the last line does not cut the ” from the script:
#!/bin/bash
FILENAME=$1
while read line
do
cut -d '"' -f2
echo $line
done < $FILENAME
$ cat file
"1" test
"2" test
"3" test
"4" test
"5" test
If I run this script with the following command:
$ ./test file
2
3
4
5
"1" test
The loop executes once.
"1" testinto variable$line.cut -d '"' -f2which reads lines 2-5 of the file (because that is the standard input at the time) and prints the number.Fix:
If, on the other hand, you want to get the numbers into a variable, you could do this in a variety of ways, including:
or: