我想在當前沒有包含緩存插件的所有網站上安裝WordPress緩存插件。我正在循環所有cPanel用戶,但在運行時會得到一些奇怪的結果。一個內膽是:bash循環沒有給出預期的結果
for i in $(ls -I . -I .. /var/cpanel/users) ; do
WPPATH=$(find /home/$i/public_html/ -type f -name wp-config.php)
WPPLUGINPATH="$(echo "${WPPATH//wp-config.php/wp-content/plugins/}")"
cd $WPPLUGINPATH
[ -d $WPPLUGINPATH*cache* ] || \
wp --allow-root plugin install cache-enabler --skip-plugins --skip-themes
sleep 3
chown -R $i: $WPPLUGINPATH
echo $WPPLUGINPATH
done
它正在爲最,但得到隨機點擊,如:
/home/userC/public_html/wp-content/plugins/
Error: This does not seem to be a WordPress install.
Pass --path=`path/to/wordpress` or run `wp core download`.
chown: missing operand after ‘userA:’
Try 'chown --help' for more information.
你可以看到的東西是關閉其引用爲用戶C尚未chown將此路徑示數約用戶A
它也說明沒有WP安裝,但如果我手動cd到該目錄,我可以運行wp-cli命令並安裝插件而不會出現問題。
另一個錯誤:
/home/userA/public_html/wp-content/plugins/
-bash: [: /home/userB/public_html/wp/wp-content/plugins/: binary operator expected
Warning: cache-enabler: Plugin already installed.
Success: Plugin already installed.
任何幫助,將不勝感激
你不應該使用'爲(LS ...'見[**擊PItfalls **](http://mywiki.wooledge.org/BashPitfalls#for_i_in_.24.28ls_.2A.mp3.29) –
也相關:[爲什麼你不應該解析'ls']的輸出(http:/ /mywiki.wooledge.org/ParsingLs)和[不要使用'for'讀取行]](http://mywiki.wooledge.org/DontReadLinesWithFor) –
此外,使用'set -x'來觀察腳本的內容一般來說,在實踐中這樣做會幫助你提出更好的問題。 –