【发布时间】:2014-06-05 08:39:33
【问题描述】:
我正在尝试在 bash 中编写一个 ksh shell 脚本来检查用户输入的字符串是否等于存储在数组中的元素。
loc_ora=/etc/oratab
osid=`sed -nr 's/^(.*):\/.*$/\1/p' $loc_ora`
set -A arr $osid
OIFS=$IFS;
IFS=" ";
read usid
case "${arr[*]}" in
* /$usid/ *)
echo -e " \t\t Entered SID Matches ... \n"
ORACLE_SID=$usid
echo -e " \t\t SID: $ORACLE_SID \n"
export ORACLE_SID
export ORACLE_HOME
;;
*)
sleep 03
echo -e " \t\t Entered SID Does not Match the System !!! \n \t\t Please Re-run the Script with a Valid SID."
sleep 02
echo -e " \t\t ABORTING !!! ..."
sleep 03
exit 0
;;
esac
IFS=$OIFS;
Error/scenario1:
I am facing a syntax error: `/' unexpected if I keep /$usid/.
Error/scenario2:
If I remove the // and keep like *$usid* in the pattern, I do not face any error but only the second *) half pattern is printing even when I provide the correct SID.
如何进行此验证?请帮忙。
谢谢, 卡提克
【问题讨论】: