[英]How to get a variable value from sh file and pass it in shell script?
我有一個 sh 文件,它獲取用戶名和密碼。 我想將其作為參數傳遞給另一個 shell 腳本。 我怎么做
fetch_credentials.sh
export user=test
export pass=test123
bash
./fetch_credentials.sh
echo "userName : "$user
echo "password : "$pass
當我執行相同的操作時,我目前得到 null 個值。
您需要獲取您的第一個文件,如下所示:
$ cat > fetch_credentials.sh
export user=test
export pass=test123
$ source fetch_credentials.sh
$ echo "userName: $user, password: $pass"
userName: test, password: test123
請注意,source 是.
所以你也可以使用. fetch_credentials.sh
. fetch_credentials.sh
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.