是否可以编写一个脚本,其中初始命令需要用户输入,以便在运行之前提示用户输入该输入?
例子:
sudo add-apt-repository ppa:"this"/"and_that"
Run Code Online (Sandbox Code Playgroud)
您可以通过以下方式在 bash 中读取用户输入:
read -p "Input this: " this
read -p "Input that: " that
sudo add-apt-repository ppa:${this}/${that}
Run Code Online (Sandbox Code Playgroud)
read 命令创建一个变量,其值取自标准输入。
在现实生活中,您还应该清理用户输入(即在调用命令之前检查非字母数字字符),但如果它只是适合您,您可以跳过它。
| 归档时间: |
|
| 查看次数: |
3591 次 |
| 最近记录: |