Bash双引号获得单引号

时间:2017-12-14 19:47:34

标签: bash

我有一个问题,我的脚本参数来自于此:

    Map<String, List<String>> tempMap = new HashMap<>();
    batches(item, 25).forEach(i -> {
        tempMap.putAll(delivery.process(i));
    }); 

对此(我使用'_rofiarg: -mesg "State: Active:Enabled"' btw剥离_rofiarg:):

cut

正如你所看到的,我有目的的双引号被忽略了,Bash将它们分成两个单词。

我会在这里重写一个伪代码,因为原始脚本对我的配置有很多本地依赖。

-mesg '"State:' 'Active:Enabled"'

在此之后我将#script1.sh # $active and $state have some value, of course script2.sh \ "_rofiarg: -mesg \"State: $active:$state\"" \ ${somearray[@]}; #script2.sh #Check input for rofi arguments, add them to Args(), all else goes to Data() for Arg in "$@"; do if [[ "$Arg" =~ _rofiarg:* ]]; then Args+=( "$(echo "$Arg" | cut -c 11-)" ); else Data+=( "$Arg" ); fi; done; 传递给目标程序,在本例中为Rofi - 就像这样:

${Args[@]}

我已经遇到这个问题好几个小时了。我所有的关于实际传递到哪个程序的陈述是使用out="$( printf '%s\n' "${Data[@]}" | rofi -config $CONF/rofi/config.cfg \ -dmenu -no-custom \ -padding $padd \ ${Args[@]}; )"; 记录的,而我在某一点,我认为我真的尝试了所有随机组合的单,双,set -o xtrace和所有其他报价类型。

1 个答案:

答案 0 :(得分:0)

      ${Args[@]};

具有未引号的变量扩展是"State:…"之间的连贯性丢失的地方。为了防止这种情况,我们必须用引号引起来,但是为了删除引号并将-mesg"State: …"分开,我们必须eval使用命令;这给出了:

out="$(
  printf '%s\n' "${Data[@]}" | 
    eval rofi -config $CONF/rofi/config.cfg \
      -dmenu -no-custom \
      -padding $padd \
      "${Args[@]}"
)"
相关问题