![](/img/trans.png)
[英]Execute a bash script from the command line which requires an argument with spaces in
[英]Bash Script execute command with argument
我正在嘗試構建新的托管服務器並遷移超過50個站點。 我需要運行此命令來使用RT Easy Engine構建每個站點。
sudo ee domain.com --php
我已經創建了帶有域的txt文件,可以毫無問題地使其循環播放。
array=()
# Read the file in parameter and fill the array named "array"
getArray() {
i=0
while read line # Read a line
do
array[i]=$line # Put it into the array
i=$(($i + 1))
done < $1
}
getArray "domains.txt"
for e in "${array[@]}"
do
echo $e
done
我將for循環更改為
echo "sudo ee " $e
工作正常。 獲取sudo ee domain.com
如何在末尾添加--php
並執行?
每次添加它,我都會
--phpe domain.com
您可以嘗試以下方法:
sed 's/\r//g' domains.txt | while read domain; do
sudo ee "$domain" --php
done
這將讀取每一行並將其存儲在變量domain
,您可以根據需要調用它。
編輯:如果您的root權限在執行過程中用完(不知道命令運行了多長時間),則首先執行sudo -i
可能會很有用。
編輯2:添加了每個請求的回車刪除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.