开发者

Offering a default on return in a shell script input prompt

I inappropri开发者_如何学JAVAately asked my question on 'How do I prompt for input in a Linux shell script?'

I've gone through the 'Questions with similar titles' list and cannot see an answer.

I obviously don't have bash4 as the following doesn't work:

$ read -e -p "Enter database SID, or just return for default: " -i "swmfolx" ORACLE_SID 
-bash: read: -i: invalid option 
read: usage: read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...] 

'All' I am trying to do is prompt for input with the option of just return for the default.

Any links or advice would be gratefully acknowledged.


You'll need to do this as follows:

read -p "Enter database SID: " dbsid
if [ "$dbsid" = "" ]
then
    dbsid="mydefaultvalue"
fi

...essentially, read the value and if all they've done is hit enter, it assigns the default value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜