我有 Ubuntu 14.04.2。我想让所有用户自动拥有一组特定的别名。我在个人 .bashrc 中设置了别名,但我不想手动将它们复制到其他用户中。理想情况下,它也应该为新创建的用户自动设置这些。
我想将我所有的登录配置集中在我的~/.bash_profile. ~/.bashrc默认情况下有一个那里,但我用一个~/.bash_profile.
但是,当我登录时,在~/.bash_profile获取源之前的某些内容并显示以下内容:
Linux ubnt10-dev1 2.6.32-38-server #83-Ubuntu SMP Wed Jan 4 11:26:59 UTC 2012 x86_64 GNU/Linux
Ubuntu 10.04.4 LTS
Welcome to the Ubuntu Server!
* Documentation: http://www.ubuntu.com/server/doc
System information as of Fri May 9 12:17:39 EDT 2014
System load: 0.01 Processes: 74
Usage of /: 5.5% of 18.58GB Users logged in: 0
Memory usage: 4% IP address for eth0: 123.x.x.x
Swap usage: 0%
Graph this data and manage this system at https://landscape.canonical.com/
New …Run Code Online (Sandbox Code Playgroud) 对于 11.04,我重新安装了我的系统。该安装的一部分是安装rvm,它rvm.sh在/etc/profile.d/. 这不起作用,因为/etc/profile(加载每个 +r in /etc/profile.d/*.sh)没有被加载。根据文档,该配置文件仅在登录时运行 bash 时才来源。为了验证这一点,我调用了bash --login,之后rvm就可用了。
这在没有任何配置的以前版本的 Ubuntu 中对我有用。也就是说,全新安装的 10.10 将正确获取 profile/.d。
我的问题是:我做错了什么,还是在 Natty 中做出的一些新假设破坏了这一点?我目前的解决方法是source /etc/profilein ~/.bashrc(这很糟糕,因为配置文件是在bashrc之前加载的,但可以解决问题)。
我试图区分这四个术语登录、非登录、交互式和非交互式:
据我了解
交互式-非登录shell:启动系统,登录系统并打开终端和
非交互式登录shell:telnet到系统并登录
但是交互式登录外壳呢?
它是否登录系统,打开虚拟终端并登录?和
非交互式 - 非登录 shell,它是否在 crontab 中运行自动脚本?
我已经读过这篇关于在哪里放置别名的帖子。
现在,假设我的自定义命令非常复杂(在输入中接受参数,由几个相继运行的命令组成,为了清楚起见,我想将其保留为多行,涉及引号、双引号等),所以我想将它定义为一个函数,例如
sshdev_system_loop () {
while true; do
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Trying to log into ststem $2 as user $1 ."
timeout 10 ssh $1@$2
done
}
Run Code Online (Sandbox Code Playgroud)
我应该把它放在.bash_aliases或 的末尾.bashrc或 中.profile吗?
一方面,我不想把它放进去,.bash_aliases因为它会“破坏”列表
alias alias_name='command/list of commands'
Run Code Online (Sandbox Code Playgroud)
另一方面,.bashrc它看起来像是操作系统管理的文件,所以我不想向其中添加内容。
那么在 Ubuntu 中将功能添加为自定义命令的最佳实践是什么?
我想在关闭终端时执行特定的 sh 脚本。
我编辑了.bash-logout文件,在 if 语句中添加了这行代码
[ -x /home/user/Documents/logout_msg.sh ] && /home/user/Documents/logout_msg
Run Code Online (Sandbox Code Playgroud)
我制作了logout_msg.sh可执行文件,并且还在 if 语句之外添加了带有 sleep 命令的基本回显消息,但是在关闭终端时没有显示。
可能是什么问题?