1
我在bash shell中定義了一個函數來搜索字符串數組,並確定輸入字符串是否存在。 它不適用於斜槓字符串。請參閱下面的代碼:在shell腳本中使用斜槓進行字符串比較
#!/bin/bash
in_array(){
search_path="$1"
shift
while [ -n "${1+defined}" ]
do
echo $1 $search_path
if [ $1 = $search_path ]
then
return 0
fi
shift
done
return 1
}
exclude_dirs=('/home/backup' '/home/xxx')
in_array 'home/backup' ${exclude_dirs[@]}
echo $?
你能解釋爲什麼嗎?