さくです。 シェルスクリプトでコマンドラインからオプションを与えたいとき、 set -- `getopt abc $*` などとしますが、これに不適切なもの(上だと -d とか)がまじっていることはどう やったら検出できるでしょうか? そんなの $? を見れば簡単だ、と思っていたのですが、 $ cat test.sh #!/bin/sh set -- `getopt abc $*` echo $? $ ./test.sh -d getopt: invalid option -- d 0 となります。 getopt(util-linux中のもの)自体はエラー時に $? に 1 を設定しているのですが、 setの次の行で $? を調べても、既にsetコマンドのステータス値(どうやら常に成 功:0)が入ってしまっているようです。 どうするのがよいでしょうか? -- OZAWA -Crouton- Sakuro E-Mail: mailto:crouton _at_ weatherlight.org Web: http://www.weatherlight.org/~crouton/ PGP: C98F 74E0 AEEB 4578 1DFC F650 3BE0 9627 11FC C9F5 VERBA VOLANT, SCRIPTA MANENT
Follow-Ups:
- Prev by Subject: [linux-users:75047] IPMasquerade for 2.2.16
- Next by Subject: [linux-users:75049] Re: getopt(1)のinvalid option検出
- Previous by thread: [linux-users:75051] Re: IPMasquerade for 2.2.16
- Next by thread: [linux-users:75049] Re: getopt(1)のinvalid option検出
- Indexes:[Main][Thread]