[英]How do I get all my terminals/shells to reload their environment by running a script?
I use my mac at home and at work. 我在家里和工作中使用我的mac。 And I use a program called Marco-polo to detect whether I am at home or at work. 我使用一个名为Marco-polo的程序来检测我是在家还是在工作。 Through this, I can get it to run a script that changes my proxy and run some scripts to configure my computer differently for the different environments like copying hosts.work and hosts.home over /etc/hosts and copy .profile.work and .profile.home over ~/.profile. 通过这个,我可以让它运行一个脚本来更改我的代理并运行一些脚本来为不同的环境配置我的计算机,例如将hosts.work和hosts.home复制到/ etc / hosts并复制.profile.work和。 profile.home over~ / .profile。
What I have not been able to do successfully so far, is to find a way to have all my running terminals reload my .profile file when I change location. 到目前为止我无法成功完成的工作是找到一种方法让我的所有运行终端在我改变位置时重新加载我的.profile文件。 Can anyone suggest a method for doing this? 有谁能建议这样做的方法?
Thanks, Tom 谢谢,汤姆
fm48 answer below in combination with this simple script (placed at /usr/bin/pkill) worked perfectly. 下面的fm48回答结合这个简单的脚本(放在/ usr / bin / pkill)工作得很好。
#!/bin/sh
sig=""
if [[ "$1" =~ - ]]; then
sig=$1;
shift
fi
for X in `ps acx | grep -i $1 | awk {'print $1'}`; do
kill $sig $X;
done
You should use a signal like SIGUSR1. 您应该使用SIGUSR1之类的信号。 First enable the signal to reload the ~/.profile with trap ". ${HOME}/.profile" SIGUSR1
. 首先启用信号以使用trap ". ${HOME}/.profile" SIGUSR1
重新加载〜/ .profile。
After that you should send all shells the SIGUSR1 signal. 之后你应该发送SIGUSR1信号的所有shell。 For example pkill -SIGUSR1 bash
if bash is the used shell. 例如,如果bash是使用过的shell,则为pkill -SIGUSR1 bash
。
如果您将Screen作为终端管理器,则可以使用以下命令向所有shell发送命令:
screen -X at \\# stuff "whatever command\\n"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.