Skip to content
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

初期値のバックスラッシュが自動的にエスケープされる #42

Open
qq542vev opened this issue Apr 5, 2022 · 1 comment

Comments

@qq542vev
Copy link

qq542vev commented Apr 5, 2022

getoptions を日頃より利用させてもらっております。開発者の皆様ありがとうございます。

以下のような ShellScript コードを作成し、 gengetoptions embed --overwrite を利用して、オプション解析のコードを追加した後実行すると、オプション -a のバックスラッシュが自動的にエスケープされるようです。

# @getoptions
parser_definition() {
  setup REST
  param a -a init:='\\'
}
# @end

# @gengetoptions parser -i parser_definition parse
# @end

parse "$@"
eval "set -- $REST"

printf '%s\n' "$a"

直接 -a を指定するとエスケープされないようです。

$ sh a
\
$ sh a -a '\\'
\\

この動作はバグでしょうか。それとも仕様でしょうか。

当方の動作環境は以下のようになります。

$ getoptions -v
v3.3.0
$ gengetoptions -v
v3.3.0
$ dpkg -l | grep dash
ii  dash                                   0.5.8-2.10                                       i386         POSIX-compliant shell
@foomin10
Copy link

foomin10 commented Dec 9, 2023

わたしは開発者ではありませんので仕様はわかりませんが、パラメーターに「バックスラッシュ バックスラッシュ」を渡しているのなら変数に「バックスラッシュ バックスラッシュ」がセットされるのは望ましい動作ではないでしょうか。

もしかして、単引用符と二重引用符の違いから「バックスラッシュ」を渡していると勘違いなさっているかもしれません。

$  printf "%s\n" "\\" '\\'
\
\\

getoptions の init:= の方は、エスケープする必要があって注意が必要です。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants