iT邦幫忙

1

Shell 詢問輸入內容,然後存成檔案

各位大大請問能否在執行.sh的時候顯示
1.請輸入姓名:(輸入的內容站存到A)
2.請輸入密碼:(輸入的內容站存到B)
然後將A跟B存入data.txt

產出檔案的樣子:
A
B

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
最佳解答

大概這樣,有問題再說
/images/emoticon/emoticon28.gif

#!/bin/bash

read -p "Enter your name :" name
read -p "Enter your password:" password

echo $name >> data.txt
echo $password >> data.txt
看更多先前的回應...收起先前的回應...
zxc170170 iT邦新手 5 級 ‧ 2018-05-08 12:51:28 檢舉

果然大神 謝謝可以

其實是問題太簡單~ /images/emoticon/emoticon56.gif

饅頭 iT邦新手 4 級 ‧ 2018-05-08 14:14:02 檢舉

如果不要顯示密碼的話可以加上 -s

應該是說這個吧

read -p "Enter your password:" -s password
zxc170170 iT邦新手 5 級 ‧ 2018-05-08 18:02:51 檢舉

因為我在學習寫shell~

me too, 剛寫半年左右~/images/emoticon/emoticon06.gif

我要發表回答

立即登入回答