问题
I want to run a shell script on startup
by google ,I found that I could add shell in rc.common
so I added the code below at the end of rc.common
is it a permission problem?
## rc.common test ##
touch ~/test.txt
reboot,there is no test.txt in my user fold
when I test it in terminal manualy ,it's ok
ls -l /etc/rc.common
-rw-r--r-- 1 guirong wheel 1737 3 30 22:36 /etc/rc.common
where is the problem? my system verison is 10.7.3 is it not ran by default in os x?
回答1:
If you want the script to be run only for the current user, you should use ~/.bashrc instead
Later edit: I misread your question. If you want something to run at startup, you should look into launchd here
回答2:
Just as an added bit of information about what was happening; /etc/rc.common runs as root, so when you were touching the file at ~/test.txt it would have been ending up in /var/root (the root user's home directory)
来源:https://stackoverflow.com/questions/9945745/rc-common-not-run-on-mac-os-x