In a Putty remote connection, I am trying to read a file line by line, cut each line by delimiter (";"), and run a command if the variables satisfy a condition. However, I get "not a valid identifier" upon reading the file.
Just some simple logic in the test.sh file:
while read download.archive
do
likes = $(echo cut -d ";" -f 1 $line)
echo $likes
dislikes = $(echo cut -d ";" -f 2 $line)
dislikes = $((dislikes * 95))
url = $(echo cut -d ";" -f 3 $line)
if [$likes -gt $dislikes]
then
youtube-dl --config-location youtube-dl-3.conf url
fi
done < download.archive
The download.archive file reads as follows-
9873;354;https://www.youtube.com/watch?v=0fd56CGnVRU
3267;54;https://www.youtube.com/watch?v=Mq4jAwPdCMw
25411;871;https://www.youtube.com/watch?v=PcSBOUpgngM
2829;44;https://www.youtube.com/watch?v=S-rj8m7Ssow
921;303;https://www.youtube.com/watch?v=JchVQMuxRVA
2014;32;https://www.youtube.com/watch?v=H8Y_ZfNViPU
Yet when I try to run ./test.sh, I get "./test.sh: line 4: read: 'download.archive': not a valid identifier"
. If the file is valid, why is it throwing an error?
read download.archive
will not work because you can't use.
in variable names. Tryawk -F';' '$1 > $2 {system("youtube-dl --config-location youtube-dl-3.conf "$3)}' download.archive
. – Mar 16 '20 at 17:06read foo.bar
:not a valid identifier
. – Mar 16 '20 at 17:07"./test.sh: line 4: read:
download.archive': not a valid identifier"` – Elie Mar 16 '20 at 17:08while read line
instead ofwhile read download.archive
. There are more errors in your script. Use https://www.shellcheck.net/ to find errors. – Bodo Mar 16 '20 at 17:10download.archive
is an invalid variable name, but it shows lots of other problems. Fix all errors. Try to explain to yourself or to us what every line of your script is intended to do. For example what do you expectwhile read download.archive
to do orlikes = $(echo cut -d ";" -f 1 $line)
? – Bodo Mar 16 '20 at 17:25while read download.archive; do echo $line; done
as an MWE i think you will spot the booboo easily enough. – bu5hman Mar 16 '20 at 17:28