- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在以编程方式更新 bash 文件。在脚本的末尾,我调用了 system("source ~/.bash_profile")
来获取 bash 文件。但是,bash 文件没有在当前 shell 中更新。
经过一些研究,我发现 system()
在子 shell 中执行。因此(我认为)当前 shell 未使用最新的 bash 文件更新。
似乎其他调用shell命令的方法也不会在当前shell中执行它们。即反引号、exec
、open3
、open4
。
如何在不打开新 shell 的情况下调用将更新当前 shell 的 shell 命令(以中断当前工作流程)?
我正在查看这些命令,包括
source ~/.bash_profile
或
alias something="echo something"
更新:建议的答案有效。因此,我调用 system("kill -SIGUSR1 #{Process.ppid}")
获取 .bash_profile。请注意,如果您使用的是 Mac,则应将建议的代码放在 .bash_profile
而不是 .bashrc
最佳答案
在你的 .bashrc.bash_profile 中:
sigusr1() {
source ~/.bash_profile
echo 'wow! I feel refreshed!'
}
trap sigusr1 SIGUSR1
现在,从您的程序中找出 bash pid(可能只是 getppid())并使用 kill() 将 SIGUSR1 发送给它。
如果拍错了过程,你会玩得很开心!这是建立新联系的某种方式,尤其是对于那些刚刚终止进程的人。
关于ruby - 如何让 'system("source ~/.bash_profile")' 与当前 shell 一起工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27731406/
我想运行一个名为“showfiles”的命令,该命令将运行命令“defaults write com.apple.finder AppleShowAllFiles TRUE”和“killall Fin
我向 .bash_profile 添加了一些设置,并且关闭/打开终端似乎没有我在那里添加的路径,即执行 echo $BLAH结果为空行。 (运行最新版本的ubuntu) 我应该改用 .profile
我试图在终端中自定义提示。为此,我尝试使用vim编辑.bash_profile,但最终得到了.bash_profile.swp文件。在网上找到一些帖子之后,我在vim中使用了:recover命令,该命
因此,我正在安装一些用于编码和个人使用的东西,并且需要在终端中运行它(如果您未阅读标题,则在Mac上运行)。 ~/.bash_profile 它只是说允许被拒绝,我正在运行OSX 10.8.4 Mou
我的 .bash_profile 中有一些简单的别名(OS X El Capitan,10.11.6)。有时,我想要多个别名来做同样的事情。例如,我有一个文件夹,它是我编程项目的起点。目前,我有一个代
我正在尝试在Mac上使用Eclipse/Maven进行开发,并且在设置环境变量时没有.bash_profile。我做ls -a,现在还不在那里。我看到一个.bash_history和.bash_ses
我在 中设置了一些别名.bash_profile 在我的 Max OS X 上。 它有效,但是当我打开一个新标签时,我总是必须加载我的 .bash_profile 文件与此命令: source ~/.
我在 ~/.bash_profile 中设置了一个别名,如下所示: alias lcmt="git show $(git log --oneline | awk '{print $1;}' | hea
这个问题在这里已经有了答案: Make a Bash alias that takes a parameter? (24 个答案) 关闭 4 年前。 我正在尝试创建一个别名,它将创建一个文件并在 V
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicate: How do I find .bash_profile and add to my shell's init
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我在我的 Mac OS X 上向我的 .bash_profile 添加了一些东西,但它们给出了一个错误。这是我现在启动终端时的全部文本日志: Last login: Thu Oct 25 23:10:
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
如何重新加载文件 .bash_profile从命令行? 我可以通过退出并重新登录让 shell 识别对 .bash_profile 的更改,但我希望能够按需执行此操作。 最佳答案 只需输入 sourc
我正在尝试从别名 (macosx) 执行 python 文件。 这可能吗? alias execute ='python path/file.py' 我正在尝试这样,但不起作用,有什么建议吗? 谢谢
我正在使用 CentOS。我从 rpm 安装了 Java8。 按照教程我这样做了: export JAVA_HOME=jdk-install-dir export PATH=$JAVA_HOME/bi
我正在尝试使用此链接中的第 5 步安装 Python 虚拟环境 Install OpenCV 3 on macOS with Homebrew (the easy way) 我在正确配置这个文件时遇到
我已经安装了 Hadoop,每次我想运行它时,首先我必须这样做: source ~/.bash_profile 否则它不会识别命令 hadoop 这是为什么? 我在 OSX 10.8 上 最佳答案 现
您好,我在远程设备上运行 linux angstrom 发行版,我将 .bash_profile 和 .bashrc 添加到/home/root,因为它们不存在,我在其中写了这个 PATH=/opt/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关闭 4 年前。 这个问题似乎不是关于 a specific programming problem,
我是一名优秀的程序员,十分优秀!