How to make the say command echo a variable value in a script?

后端 未结 2 1513
被撕碎了的回忆
被撕碎了的回忆 2021-01-28 10:17

I\'m on a Mac and sometimes I use the say command at the end of my scripts, like so:

system(\'say \"Finished successfully\"\')

But

2条回答
  •  佛祖请我去吃肉
    2021-01-28 11:04

    Either remove the system or remove the backticks:

    a = "hello"
    #=> "hello"
    `say '#{a}'`
    #=> ""
    system("say '#{a}'")
    #=> true
    

    Since you edited your post to be single quotes instead of backticks, single quotes cannot support string interpolation, see this question for more details.

提交回复
热议问题