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

后端 未结 2 1511
被撕碎了的回忆
被撕碎了的回忆 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 10:48

    Remove backticks (Kernel#`):

    system("say \"#{my_variable}\"")
    

    or

    system("say '#{my_variable}'")
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题