ruby - 为什么在 bash 上执行 ruby​​ 命令到命令文件不起作用?

标签 ruby bash

.command 文件中的代码:

cd "$(dirname "$0")" 
g1=Hi-Lo
echo Welcome to Ruby_Games! So far, you can play $g1.
echo What game would you like to play?
read game_choice
if [$game_choice == $g1]
then
ruby Hi-Lo.rb
fi

输出:

Welcome to Ruby_Games! So far, you can play Hi-Lo.
What game would you like to play?
Hi-Lo
/Users/Abbas/Desktop/Ruby_Games/LAUNCHER.command: line 6: [Hi-Lo: command not found
logout

那么到底出了什么问题呢?谢谢

最佳答案

我相信您的 if 语句中需要双引号

类似于此处的示例 6.4:http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html

cd "$(dirname "$0")" 
g1=Hi-Lo
echo Welcome to Ruby_Games! So far, you can play $g1.
echo What game would you like to play?
read game_choice
if [ "$game_choice" = "$g1" ]
then
    ruby Hi-Lo.rb
fi

关于ruby - 为什么在 bash 上执行 ruby​​ 命令到命令文件不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44793074/

相关文章:

linux - 错误 : ld. 所以:无法预加载对象 LD_PRELOAD:忽略

java - 了解脚本和程序之间的区别

node.js - 通过 bash 使用 npm 在 vagrant guest 上安装 gulp

bash - 如何更改 $PATH 的顺序?

ruby-on-rails - 跟踪谁在 Rails 中做了什么?

ruby-on-rails - 如何阻止 Rails Controller 中的业务逻辑

ruby-on-rails - 如何保证回调顺序?

ruby - 遍历日期以查找日期之间的天数

jquery - 如何让相同的 javascript 代码响应多个 ajax 调用?

mysql - 如何使用 ssh 从命令行执行 init 脚本