Why in the following bash script doesn't $ID
in the find
line have any value during the first iteration of the while loop?
while read -r ID
do
echo $ID
cd "`find . -iname "*($ID)"`" # ← This is the problem line.
pwd
cd -
echo
done < IDs.csv
Here's the trace of the first iteration
+ read -r ID
+ echo 6518
6518
++ find . -iname '*(6518)' # ← find always returns nothing first iteration.
+ cd ''
+ pwd
/home/Geremia
+ cd /home/Geremia
+ echo
But successive iterations work just fine:
+ read -r ID
+ echo 6556
6556
++ find . -iname '*(6556)' # ← find returns path all successive iterations.
+ cd './found/dir (6556)'
+ pwd
/home/found/dir (6556)
+ cd /home/Geremia
+ echo
This always occurs, even if I put 6556
, for example, at the beginning of the CSV file.