[英]Defining bash aliases from Ruby script
I'm trying to set a Bash alias from a Ruby script. 我正在尝试从Ruby脚本设置Bash别名。 The intended functionality would be (from the Ruby script):
预期的功能将是(来自Ruby脚本):
alias foo="cd /bar/blah"
) alias foo="cd /bar/blah"
) However, using the system
command doesn't work because it launches a new subshell. 但是,使用
system
命令不起作用,因为它会启动一个新的子shell。
Any advice? 有什么建议吗?
what you want to do is not doable. 您想做的事是不可行的。
the script you are launching cannot really alter the environment of the shell. 您启动的脚本不能真正改变外壳环境。
one way to do this would be to source the output of the ruby script and to have the script just generate the commands. 一种方法是获取ruby脚本的输出,并使脚本仅生成命令。 This way you are instructing the shell to actually do the right thing.
这样,您就指示外壳实际执行正确的操作。
something like 就像是
source $(my_ruby_script.rb)
have the script alter the aliases and at the end read and print out the file. 让脚本更改别名,最后读取并打印文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.