简体   繁体   English

Ruby Net / SSH-重新加载bash_profile

[英]Ruby Net/SSH - reload bash_profile

I'm using Ruby MRI 1.8.7 and I have a Net-SSH script that connects to a server and edits the .bash_profile file. 我正在使用Ruby MRI 1.8.7,并且有一个Net-SSH脚本连接到服务器并编辑.bash_profile文件。 Basically a few alias shortcuts are added. 基本上,添加了一些别名快捷方式。 Example of .bash_profile content: .bash_profile内容示例:

alias test="echo 'test'"

Now, I cannot use those aliases until I reload via source .bash_profile.. The problem is that it seems like I cannot source .bash_profile via Net-SSH. 现在,在通过源.bash_profile重新加载之前,我无法使用这些别名。问题是,似乎无法通过Net-SSH源.bash_profile。 This is what I've tried so far: 到目前为止,这是我尝试过的:

ssh.exec!("source .bash_profile")
ssh.exec!("source /root/.bash_profile")
ssh.exec!("bash -c 'source ~/.bash_profile'")

Now, actually I don't even need the aliases in Net-SSH, but I at least don't want to source bash_profile manually on the server. 现在,实际上我什至不需要Net-SSH中的别名,但至少我不想在服务器上手动获取bash_profile。 What is the issue here, and are there any solutions to that? 这里的问题是什么,对此有什么解决方案?

You can't have a bang (!) in a double-quoted string in bash. bash中的双引号字符串中不能包含“ bang”(!)。 Try this: alias test='echo ''test!''' 试试这个: alias test='echo ''test!'''

puts

source $HOME/.bash_profile

at first line of .bashrc .bashrc的第一行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM