unable to pass wget a variable with quotes inside the variable

后端 未结 2 921
小蘑菇
小蘑菇 2020-12-22 11:40

I am trying to script a wget command to download a web page and all it\'s attachments and jpegs etc.

When I enter the script by hand, it works, but I need to run thi

2条回答
  •  甜味超标
    2020-12-22 12:33

    Quotes inside of quoted strings or variables are ordinary characters, not quoting characters. There's no way to change that. Use an array instead:

    A=(a b 'c d' 'e f')
    cmd "${A[@]}"
    

    calls cmd with four arguments a, b, c d, and e f.

    (You could achieve a similar effect with eval, but that's a lot more error prone. In your case, using arrays is much more convenient.)

提交回复
热议问题