I have a script which runs a database query and redirects the result to a csv file and after using sftp to upload it, the file is removed like this:
FileName=` echo "report_$StartDate:$StopDate.csv" | sed 's/\ /_/g'`
$DatabaseCommand "$Query" -f CSV | sed 's/"//g' > "$ReportDir/$FileName"
expect<<EOD
set timeout 3600
spawn sftp $USER@$HOST
expect "password:"
send "$PASSWORD\r"
expect "sftp>"
send "put $ReportDir/$FileName\r"
expect "sftp>"
send "bye\r"
EOD
rm -rf $ReportDir/$FileName
I know tha last line should be changed to rm -f, but I'm wondering is there any way that bash could mix up in the FileName line and be able to run the following command instead:
rm -rf $ReportDir/
FileNameturns out to be empty, or starts with spaces so because of your lack of quoting, gets split up?FileNamebecomes something likereport_*:*.csvand you end up deleting all those files in the directory?