开发者

How can I read an IP address from the user in a bash script?

if [ "$1" == "-s" ]; then
  echo "Connecting to host.."
  scp root@IP_ADDRESS:/private/var/mobile/Library/SMS/sms.db /private/var/mobile/Media/开发者_StackOverflow社区BackupSMS
  echo " "
  exit
fi

I need to ask user for a IP-address, that will then be placed where IP_ADDRESS is above. I'm new to scripts, but I'm trying.

How would I do this?


Use the built in read command

read IP_ADDRESS

or, if you want a nice prompt:

read -p "Enter ip address: " IP_ADDRESS

and then add a $ to the scp line:

scp root@$IP_ADDRESS:/...
         ^
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜