Reputation: 1298
I'm working on a script that takes commands from MySQL and executes them one by one. My problem is I can't execute the commands from script:
./bash.sh: line 26: /myscript.sh -c "": no such file or directory
Line 26 is the command I wish to execute ("$com"). if i try to run the command manually, by echoing the content of "$com" and than run it from terminal, it's working.
What am I doing wrong?
if [ ! "${#array[*]}" -eq "0" ]; then
for (( i=0 ; i<cnt ; i++ )); do
id=$(echo "${array[$i]}" | sed 's@\t@^@g' | cut -f'1' -d'^')
com=$(echo "${array[$i]}" | sed 's@\t@^@g' | cut -f'2' -d'^')
imp=$(echo "${array[$i]}" | sed 's@\t@^@g' | cut -f'3' -d'^')
if [[ "$id" = [0-9]* ]]; then
"$com"
echo "DELETE FROM list WHERE id='$id'" | mysql "$DB_USER" -u "$DB_USER" -p"$DB_PASS"
fi
done
else
echo "The list is empty"
fi
Upvotes: 1
Views: 2557
Reputation: 19375
Change
"$com"
rather to
$com
(remember: too many quotes can be as harmful as too few)
than to
eval "$com"
eval
just to undo the unwanted effect of quoting.Upvotes: 1
Reputation: 2605
Added as Community Wiki
This question was solved in the comments by Vaughn Cato and the OP hasn't been seen since March.
The accept answer there was to use eval
so the if statement in the script would be:
if [[ "$id" = [0-9]* ]]; then
eval "$com"
echo "DELETE FROM list WHERE id='$id'" | mysql "$DB_USER" -u "$DB_USER" -p"$DB_PASS"
fi
Upvotes: 4