为什么\`some nonexistent command\`和`\`"some nonexistent command"\`的行为不同?
irb> \`nonexistent_command\`
Errno::ENOENT: No such file or directory - nonexistent_command
in ``'
irb> \`"nonexistent_command"\`
sh: nonexistent_command: command not found
=> ""为什么会这样呢?
发布于 2015-05-21 22:17:17
当你使用反引号时,那就是告诉ruby去尝试运行那个系统命令。您将从找不到该命令或文件的操作系统返回一个"Error no entry“(ENOENT)错误。
当你使用双引号时,你正在创建一个字符串,这是没有问题的。
思考的食粮:也许你的意思是使用单引号(这只是一个字符串,它不会进行变量插值)而不是反引号?
https://stackoverflow.com/questions/30376020
复制相似问题