我一直在試圖編寫一個shell腳本來檢測虛擬linux = Ubuntu 16.0.4機器上的作曲家和混帳,然後在需要時安裝它們。 +如果機器準備好了,則克隆所需的存儲庫。 現在,這是我第一次嘗試編寫任何類型的腳本,也很抱歉,如果我以某種方式搞砸了這個問題本身,我現在也在使用stackoverflow。在Linux上運行.sh腳本時出現語法錯誤。我究竟做錯了什麼?
任何幫助表示讚賞,在此先感謝。
這是我最初接收到的原始任務說明:
-check如果要是這樣安裝在服務器 混帳,克隆回購與代碼庫
-check如果要是這樣安裝在服務器 作曲家,作曲安裝在laravel應用程序的根目錄
- 最後,PHP工匠遷移--seed
現在,這是我是如何努力實現這一目標:
#!/bin/bash
echo "The installation process is about the begin..."
if ! which git;
then echo "Git has been located on the destination system. Cloning begins..."
git clone <link to the gitlabe repo>
else echo "There is no Git installed on the system. Git installation commences..."
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git
echo "Cloning begins..."
git clone <link to the gitlabe repo>
fi
if ! which composer;
then
echo "Composer has been located on the destination system."
else
echo "There is no Composer installed on the system. Composer installation commences..."
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install composer
fi
sudo apt-get update
sudo apt-get install curl php5-cli git
curl -sS https://getcomposer.org/installer | sudo php -- --install- dir=/usr/local/bin --filename=composer
composer global require "laravel/installer"
sudo apt-get update
'Now the preferred version in the vagrantfile has to be edited to be 1.8.1 instead of 1.9'
'Generate a ssh key'
ssh-keygen -t rsa -b 4096 -C "< e-mail adress that I used >"
'Start ssh agent eval $'
ssh-agent -s
'Add your SSH private key to the ssh-agent'
ssh-add -K ~/.ssh/id_rsa
php artisan migrate --seed
錯誤消息我收到:
sudo sh ./testscript.sh
[sudo] password for linuxtest:
The installation process is about the begin...
: not foundt.sh: 3: ./testscript.sh:
: not foundt.sh: 4: ./testscript.sh:
: not foundt.sh: 5: ./testscript.sh:
./testscript.sh: 72: ./testscript.sh: Syntax error: end of file unexpected (expecting "then")
在hashbang中添加「-x」可以讓你更深入地瞭解正在發生的事情('#!/ bin/bash -x')。其餘部分,「[」和「]」需要空格,如'if [!哪個git];那麼...'。但是這可能是由此處的格式造成的 – Ronald
代碼中存在很多錯誤。嘗試使用https://www.shellcheck.net。 – pacholik
我添加了空格和「-x」但沒有變化,看起來好像是 –