English 中文(简体)
我怎么能消除指挥线中的yn误?
原标题:How can I eliminate syntax error in command line?
  • 时间:2012-05-01 16:21:26
  •  标签:
  • bash

How can I eliminate syntax error in command line? I created a bash script like this:

#!/bin/bash

USER="$@"

sed  s/[!@#$%^&*()]//g > $@
done

if ! [ -f $@ -a -r $@ ] ; 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

Actually, this is a script which insert data from text files to database table. and as you can see, I want to check file existence before insert text files.

我试图利用tr——指挥和指挥,以消除指挥线上的yn误,但我认为这行不通。

我期望:

$ ./script.sh test!rr.txt
Wrong Option : test!rr.txt is not readable or not exist

Do you have any idea? Thanks.

问题回答

在试图评价这一路线之前,她将<代码>!解释为历史指挥。 提审:

$ ./script.sh test!rr.txt

如果你想在档案中包含血清特征,请在上面引述:

$ ./script.sh  test!rr.txt 

你需要调整你们的期望。 Bash只是做你告诉它的事情:在把论点传给你的文字之前,进行历史扩张。 关于援引“......”论点或其他理由的其他答案是正确的,但是它们认为,在把论点传给你的文字之前,历史扩张正在发生(在你可以核实档案存在的地方)。

2. 引言中的参数是为了防止空壳解释特殊标志:

$ ./script.sh "test!rr.txt"




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签