3
奇妙なことに、[[ 111-11-1111 =~ "[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]" ]]
はコマンドラインで成功します。REマッチング演算子はこのスクリプトでは機能しません
しかし、このスクリプトは同じを生み出すことができないとき、私bash re.sh 111-11-1111
#!/bin/bash
# re.sh
input=$1
if [[ "$input" =~ "[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]" ]]
# ^NOTE: Quoting not necessary, as of version 3.2 of Bash.
# NNN-NN-NNNN (where each N is a digit).
then
echo "Social Security number."
# Process SSN.
else
echo "Not a Social Security number!"
# Or, ask for corrected input.
fi
なぜですか?
可能な重複が(http://stackoverflow.com/questions/218156/bash-regex-with-quotes) –
I bashを使用しています4.3とそれはif:[["$ input" =〜[0-9] [0-9] [0-9] - [0-9] [ 0-9] - [0-9] [0-9] [0-9] [0-9]]] '。 'bash -x re.sh'はqoutesが存在するいくつかの奇妙なことを明らかにします。 –