我試圖以另一個用戶的身份運行命令並以該用戶的身份讀取輸入。由於某些原因,腳本不會在read
命令中暫停,我不確定原因。下面是腳本的例子:Bash腳本不等待閱讀
#!/bin/bash
username='anthony'
sudo -H -u "$username" bash << 'END_COMMAND'
# Commands to be run as new user
# -------------------------------
echo "#! Running as new user $USER..."
echo "#! Gathering setup information for $USER..."
echo -n "Enter your name and press [ENTER]: "
read name
echo -n "Enter your email and press [ENTER]: "
read email
END_COMMAND
echo "Done"
任何想法,這是爲什麼不停止在read name
或read email
?
很好的答案,謝謝。 – alukach 2012-08-09 22:36:20