I have about 10k (approx 180x50x2) CSV files which I want to join together as following, but the inner for loop fails because of some syntax error; I cannot see the error in lastFile
#!/bin/bash dir='/home/masi/CSV/' targetDir='/tmp/' ids=(118 119 120) channels=(1 2) for id in ids; do for channel in channels; # example filename P209C1T720-T730.csv lastFile="$dir'P'$id'C'$channel'T1790-T1800.csv'" # show warning if last file does not exist if [[ -f $lastFile ]]; then echo "Last file "$lastFile" is missing" exit 1 fi filenameTarget="$targetDir'P'$id'C'$channel'.csv'" cat $dir'P'$id'C'$channel'T'*'.csv' > $filenameTarget done; done Error
makeCSV.sh: line 12: syntax error near unexpected token `lastFile="$dir'P'$id'C'$channel'T1790-T1800.csv'"' makeCSV.sh: line 12: ` lastFile="$dir'P'$id'C'$channel'T1790-T1800.csv'"' OS: Debian 8.5
Linux kernel: 4.6 backports
doin your secondforloopdoin the secondforloop. Are you really sure that there is ado?doin the previous line is thedofor the firstforloop. The secondforloop needs anotherdo. Syntax offorloop:for name in list; do commands; done.