简体   繁体   English

如何在bash脚本中读取用户的IP地址?

[英]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/BackupSMS
  echo " "
  exit
fi

I need to ask user for a IP-address, that will then be placed where IP_ADDRESS is above. 我需要询问用户一个IP地址,然后将其放在IP_ADDRESS所在的位置。 I'm new to scripts, but I'm trying. 我是脚本的新手,但我正在努力。

How would I do this? 我该怎么做?

Use the built in read command 使用内置的read命令

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行添加$

scp root@$IP_ADDRESS:/...
         ^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM