我使用shell腳本來配置我的服務器。修改.bashrc文件後,我需要退出然後重新登錄才能重新啓動shell。Bash shell腳本:我如何退出並重新啓動腳本?
su vagrant <<'EOF'
echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
echo "export PROJECT_HOME=/var/www" >> ~/.bashrc
echo "alias mkvirtualenv='mkvirtualenv --no-site-packages'" >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
source ~/.bashrc
// this is where I need help, i need to exit the shell and relogin. then run mkvirutalenv command.
mkvirtualenv test1
EOF
更新:
這是shell腳本文件遊民運行。
#!/usr/bin/env bash
if [ -f "/var/vagrant_provision" ]; then
exit 0
fi
echo "Installing Flask environment and setting it up.."
echo "------------------------------------------------"
apt-get update >/dev/null 2>&1
echo "1. update is done"
#apt-get upgrade -y >/dev/null 2>&1
echo "2. upgrade is done -- skipped for dev"
rm -rf /var/www
ln -fs /vagrant /var/www
echo "3. Symbolic link is created"
apt-get install -y build-essential python-dev >/dev/null 2>&1
apt-get install -y curl >/dev/null 2>&1
echo "4. curl is installed"
apt-get install -y python-pip >/dev/null 2>&1
echo "5. pip is installed"
pip install virtualenv virtualenvwrapper >/dev/null 2>&1
echo "6. virtualenv and virtualenvwrapper are installed"
su vagrant <<'EOF'
echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
echo "export PROJECT_HOME=/var/www" >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
echo "alias mkv='mkvirtualenv --no-site-packages'" >> ~/.bashrc
echo "alias mycmd='ls'" >> ~/.bashrc
source ~/.bashrc
mycmd
mkv test1
EOF
echo "7. add environment variables to .bashrc"
echo "8. source .bashrc"
echo "9. test1 environment is created"
touch /var/vagrant_provision
echo "------------------------------------------------"
echo "Installation is done"
這是我得到的輸出。仍然沒有找到命令。
Installing Flask environment and setting it up..
------------------------------------------------
1. update is done
2. upgrade is done -- skipped for dev
3. Symbolic link is created
4. curl is installed
5. pip is installed
6. virtualenv and virtualenvwrapper are installed
bash: line 8: mycmd: command not found
bash: line 9: mkv: command not found
7. add environment variables to .bashrc
8. source .bashrc
9. test1 environment is created
------------------------------------------------
Installation is done
爲什麼要退出然後重新登錄以重新啓動shell?您正在使用源命令。所以所有的變化都會得到反映。如果你真的想使用新的shell,你可以使用bash mkvirtualenv test1。 – virus
@virus我必須退出並重新登錄。否則,我將收到此錯誤消息「mkvirtualenv:命令未找到」和「bash mkvirtualenv test1」沒有工作。 – qinking126
#!/ usr/bin/sh echo「alias mycmd ='ls'」>>〜/ .bashrc source〜/ .bashrc mycmd 我正在運行此工作正常。爲什麼不在你的情況下? – virus