簡體   English   中英

如何在bash腳本中將第一行用戶類型讀入終端

[英]How to read the first line user types into terminal in bash script

我試圖寫一個腳本在哪里運行腳本,用戶將沿着

$./cpc -c test1.txt backup

進入終端,。/ cpc將在其中運行腳本,-c是$ option,test1.txt是$ source,備份是$ destination。

我如何將輸入的值分配給終端以在腳本中使用它們,例如在

if [[ -z $option || -z $source || -z $destination ]]; then
    echo "Error: Incorrect number of arguments." (etc)

與聯機檢查腳本時一樣,將返回以下錯誤:“已引用但未分配選項/源/目標。”

抱歉,如果其中任何一個都沒有道理,我會盡量清楚

參數存儲在編號參數$1$2等中。因此,只需分配它們即可

option=$1
source=$2
destination=$3

另請參閱man getoptman bash getopts

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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