-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
部分同步容器无法正确处理包含空格的 EXCLUDE/EXTRA #111
Comments
参考 superuser stackexchange 的方法: $ EXTRA="--user-agent 'Test client'"
$ extra_array=()
$ while IFS= read -r -d '' arg; do extra_array+=("$arg"); done < <(echo "$EXTRA" | xargs printf '%s\0')
$ echo "${extra_array[@]}"
--user-agent Test client
$ ./args "${extra_array[@]}"
2 args: <--user-agent> <Test client> 其中 #!/bin/sh -
printf "%d args:" "$#"
printf " <%s>" "$@"
echo |
$ EXTRA="--exclude='.*' --exclude='.*/' --include='Raspberry_Pi_Education_Manual.pdf' --include=imager/ --include='raspios_.+/' --include=rpd_x86/"
$ extra_array=()
$ while IFS= read -r -d '' arg; do extra_array+=("$arg"); done < <(echo "$EXTRA" | xargs printf '%s\0')
$ ./args $EXTRA
6 args: <--exclude='.*'> <--exclude='.*/'> <--include='Raspberry_Pi_Education_Manual.pdf'> <--include=imager/> <--include='raspios_.+/'> <--include=rpd_x86/>
$ ./args "${extra_array[@]}"
6 args: <--exclude=.*> <--exclude=.*/> <--include=Raspberry_Pi_Education_Manual.pdf> <--include=imager/> <--include=raspios_.+/> <--include=rpd_x86/> |
bash 的分词是有点蛋疼.. 除了 superuser 里提到的这种方式外,我感觉可以改一下 entrypoint 让它把 当初通过环境变量传参这种方式的意图是希望设置 flag 的值,而不是传一系列 flag。现在看这样也挺麻烦的,尤其是同步程序的 flag 比较多的时候😂。看你们觉得怎么处理比较合适了。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
预期行为
当环境变量为:
的时候,被 exec 的最终的程序能够知道
--some-arg
的参数是"Test String"
实际行为
当写成:
的时候,shell 实际会(非预期地)拆成
--some-arg '"Test' 'String"'
,那么--some-arg
的参数就是"Test
了。并且在有
*
的情况下,shell 可能会尝试进行文件名匹配(虽然几乎所有情况下都会失败)复现步骤
EXTRA: --user-agent "Example Tool"
exec ... $EXTRA
=>error: unexpected argument 'Tool"' found
目前的同步程序中可能受影响(用
rg -F -- "--"
搜索)的有 (fixed or not):lftpsync 的命令设计看起来不受此影响。
补充信息
https://superuser.com/a/1529316
The text was updated successfully, but these errors were encountered: