我怎樣才能消除在命令行語法錯誤? 我創建了一個bash腳本是這樣的:如何消除命令行中的語法錯誤?
#!/bin/bash
USER="[email protected]"
sed 's/[[email protected]#\$%^&*()]//g'> [email protected]
done
if ! [ -f [email protected] -a -r [email protected] ] ; then
echo "Wrong Option : "${USER}" is not readable or not exist" >&2
exit -1
fi
cat "${@}"|while read -r line
do
IFS=, read -r f1 f2 f3 f4 f5 <<< "$line"
mysql --user=user --password=password --database=database <<EOF
INSERT INTO table_name VALUES($f1,'$f2','$f3','$f4',$f5);
EOF
done
,我執行這個腳本在其他終端是這樣的:
$ ./script.sh test!rr.txt
-bash: !rr.txt: event not found
其實,這是插入來自文本文件中的數據以數據庫表的腳本。 ,正如你所看到的,我想之前插入文本文件,檢查文件是否存在。
我試圖使用TR -d命令和sed命令,以消除對命令行語法錯誤,但我認爲它不工作..
我的期望是:
$ ./script.sh test!rr.txt
Wrong Option : test!rr.txt is not readable or not exist
你有什麼想法? 謝謝。