我剛開始學習PHP。我遵循phpacademy's教程,我會推薦給任何人。無論如何,我使用XAMPP來測試我的腳本。我試圖編寫一個bash腳本來啓動XAMPP,然後如果它找到一個特定的字符串「XAMPP for Linux started」,然後打開firefox到本地主頁,它已經從終端重定向到文件xampp.log。我在搜索文件時遇到問題。我一直得到一個:用bash腳本搜索字符串的日誌文件
grep: for: No such file or directory
我知道文件存在,我認爲我的語法是錯誤的。這是我到目前爲止有:
loaded=$false
string="XAMPP for Linux started."
echo "Starting Xampp..."
sudo /opt/lampp/lampp start 2>&1 > ~/Documents/xampp.log
sleep 15
if grep -q $string ~/Documents/xampp.log; then
$loaded=$true
echo -e "\nXampp successfully started!"
fi
if [$loaded -eq $true]; then
echo -e "Opening localhost..."
firefox "http://localhost/"
else
echo -e "\nXampp failed to start."
echo -e "\nHere's what went wrong:\n"
cat ~/Documents/xampp.log
fi
用於調試,'set -vx'或將shebang更改爲'#!/ bin/bash -x'的標準技巧,並檢查是否所有內容都已擴展爲exxpected –