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

前端 未结 5 1129
闹比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 04:00

    Answering my own question. BIG thanks goes to pzanoni. xargs seems to parse correctly anything you are throwing to it :-) "$@", "$", $@ and $ works good with it. So my code now looks like:

    #!/bin/sh
    
    pass() {
        echo $* | xargs ./sh_param
    }
    
    pass '"single param" separate params'
    

    And result is what I wanted:

    Param: single param
    Param: separate
    Param: params
    

提交回复
热议问题