Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为ruby脚本创建shell命令_Ruby_Shell_Unix - Fatal编程技术网

为ruby脚本创建shell命令

为ruby脚本创建shell命令,ruby,shell,unix,Ruby,Shell,Unix,假设我有一个ruby脚本,它可以打印一些消息,比如helloworld 现在,我可以自定义shell命令,比如printMessage,将控件传递给我的ruby脚本吗 因此,每当我从命令行键入printMessage,它都会打印Hello World?将其添加到.bashrc或.bash\u配置文件中 alias printMessage='ruby /path/to/file.rb' 我应该这样做。除非我误解了这个问题 并且,put将打印到命令行。完成此操作后,您必须重新加载bash配置文件

假设我有一个ruby脚本,它可以打印一些消息,比如
helloworld

现在,我可以自定义shell命令,比如
printMessage
,将控件传递给我的ruby脚本吗


因此,每当我从命令行键入
printMessage
,它都会打印
Hello World

将其添加到.bashrc或.bash\u配置文件中

alias printMessage='ruby /path/to/file.rb'
我应该这样做。除非我误解了这个问题

并且,
put
将打印到命令行。完成此操作后,您必须重新加载bash配置文件才能使其正常工作。只需键入
source~/.bashrc
即可重新加载它

可能需要
chmod
文件

备选方案:

alias printMessag='ruby -e "puts \"Hello World\""'

也应该可以。

让ruby文件作为可执行文件运行应该可以实现您想要的,对吗?有很多方法可以做到这一点,但这个问题更适合我们。