如何编写在登录时执行的shell脚本?

dub*_*bex 22 login ubuntu shell-script profile

我正在尝试在 Ubuntu 11.10 Linux 发行版中编写 bash shell 脚本,它将在登录系统时自动执行。但我无法弄清楚在脚本中写什么,它会在登录时自动执行。

小智 32

如果您希望它是全局的,请修改

 /etc/profile 
Run Code Online (Sandbox Code Playgroud)

或添加脚本

 /etc/profile.d
Run Code Online (Sandbox Code Playgroud)

如果您希望它特定于用户,请修改

 ~/.profile
Run Code Online (Sandbox Code Playgroud)

  • 如果您将脚本放在“/etc/profile.d/”中,请不要忘记扩展名应该是“.sh”。`chmode +x /etc/profile.d/myscript.sh` 当然也是。 (3认同)