gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:06:18 26 4
gpt4 key购买 nike

.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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com