How to pass command line parameters with quotes stored in single variable?

前端 未结 5 1125
闹比i
闹比i 2021-01-07 03:58

I want to call external application from shell script, but this shell script gets parameters (from other script) in a single variable. All was OK until I did not have to use

5条回答
  •  醉酒成梦
    2021-01-07 03:59

    If you're stuck with a single variable, you'll have to use eval:

    $ show() { i=0; for param; do ((i++)); echo "$i>$param"; done; }
    
    $ show '"single param" separate params'
    1>"single param" separate params
    
    $ eval show '"single param" separate params'
    1>single param
    2>separate
    3>params
    

    Note that the double quotes are eaten by the shell.

提交回复
热议问题