簡體   English   中英

如何在bash / unix腳本中檢測用戶輸入?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM