開機後自動執行script - Linux

Table of Contents

大家好 我想請問一下

我在/home底下寫了一隻script然後a.sh

我希望每次開機以後都會執行這支script

假設內容只有

echo "hello word"

我希望每次打完密碼進來以後他就先執行然後show出hello word

我參考網路上作法

想自動執行一些 shell script或指令可以直接編輯 /etc/rc.local 檔案

所以我就在裡面寫了 bash /home/a.sh

但沒有成功,想請問一下該怎麼做呢?

謝謝大家

--

All Comments

Tristan Cohan avatarTristan Cohan2016-03-14
打完密碼進來->這個應該是進bash的時候吧
那這種的你應該要寫在.bashrc或.bash_profile裏面
Bethany avatarBethany2016-03-14
.bash_profile只會在bash登入時執行,子程序的bash下不會,
所以如果你只是要在登入時跑這個,那你應該寫在.bash_profi
le。
Agnes avatarAgnes2016-03-17
如果你原先沒有在用.bash_profile,那建議.bash_profile的
開頭加一行這個:
[[ -r ~/.bashrc ]] && . ~/.bashrc
這樣登入時才會跟著讀入.bashrc
Sandy avatarSandy2016-03-22
感謝大大
Edwina avatarEdwina2016-03-23
[ -r xxxx ] && .... 就好,[[ -r xxxx ]] 多一組了
Skylar DavisLinda avatarSkylar DavisLinda2016-03-23
原來@@
Frederic avatarFrederic2016-03-23
新規格建議用兩個[框起來的說...
Isla avatarIsla2016-03-24
我是記得群組方式一同判斷用 [[ ]] 比較直覺與簡單
Freda avatarFreda2016-03-25
若單純只是 [ -r xxxx ] 判斷單一項目應該就還好