Shell script pass arguments with spaces

前端 未结 2 562
粉色の甜心
粉色の甜心 2020-12-22 00:28

I want to pass arguments from one shell script ( say script1 ) to another. Some of the arguments contain spaces. So I included quotes in the arguments and before passing to

2条回答
  •  庸人自扰
    2020-12-22 01:04

    Embedding quotes in a variable's value doesn't do anything useful. As @Etan Reisner said, refer to http://mywiki.wooledge.org/BashFAQ/050. In this case, the best answer is probably to store FL as an array, rather than a plain variable:

    FL=(-filelist "/Users/armv7/My build/normal/My build.LinkFilelist" -filelist "/Users/arm64/My build/normal/My build.LinkFilelist")
    

    Note that the quotes aren't stored as part of the array elements; instead, they're used to force the paths to be treated single array elements, rather than broken up by the spaces. Then refer to it with "${FL[@]}", which makes bash treat each element as an argument:

    script2 -arch armv7 -arch arm64 -isysroot /Applications/blahblah/iPhoneOS8.1.sdk "${FL[@]}"
    

提交回复
热议问题