How do I break up an extremely long string literal in bash?

后端 未结 6 1122
独厮守ぢ
独厮守ぢ 2021-01-30 10:21

I would like to embed a long command like this in a bash script:

mycommand \\
    --server myserver \\
    --filename extremely/long/file/name/that/i/would/like/         


        
6条回答
  •  情话喂你
    2021-01-30 11:17

    Basically, there is nothing built into bash to do this.
    A wrapper is typically more trouble than it's worth, but that said, you could try an alias or a funciton, eg. j

    j(){sed -e ':a;$!N;s/ *\n *//g;ta' <<<"$1"}
    
    echo "$(j "3   spaces  
               /hello
               /world
               /this
               /is
               /a
               /long
               /path
              ")"
    
    # 3   spaces/hello/world/this/is/a/long/path
    

提交回复
热议问题