[英]How to detect user input in bash/unix scripting?
我正在处理一个小的脚本,部分问题是找到可以使用的正确文件。 该脚本设置工作目录并提示用户输入文件名,如下所示:
#!/bin/bash
#Now to set the directory for the user files, which will be used to execute the$
#cd "$(M:/ "$0")" // to be used on campus machines only
#using it at home will break the script due to not being on the M:/ drive
echo We are currently working from the M directory.
echo Please enter the bash script name, which should be formatting as username.
如何读取用户的输入(或什至允许用户输入某些内容然后阅读),然后将其用于打开同一目录中的文件?
我会使用变量并将用户输入分配给它还是其他一些东西?
谢谢!
您可以使用read
功能
echo -n "Enter your name and press [ENTER]: "
read name
echo -n "Enter your gender and press [ENTER]: "
read -n 1 gender
echo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.