1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

nc で "--" 以降の引数が無視される

Posted at

次のようにすると "--" 以降の文字は無視されます。

$ nc localhost 7 -- -a -b -c -d -e --help hoge

ncgetopt で引数を解釈していて getopt は引数に "--" が現れるとそれ以降の文字をオプションとして認識しなくなります。

普通は "-" で始まるファイル名などをオプションとして認識させずに指定するために使います。

$ touch -- -a
$ rm -- -a

一方 nc は3番目以降のオプションではない引数を無視します。例えば下記の unko の部分は無視されます(-l なら2番目以降かも)。

$ nc localhost 7 unko

3番目以降の引数でも "-a" のようにオプションとして解釈される場合は(それがオプションとして正しくなければ)エラーになります。

$ nc localhost 7 -a
nc: invalid option -- 'a'

次のように "--" を入れてやると "-a" とかはオプションではない3番目以降の引数になるので無視されます。

$ nc localhost 7 -- -a -b -c -d -e --help hoge

あくまで3番目以降のオプションでは無い引数が無視されているのであって "--" に引数を無視させるような効果があるわけではありません。

用途

思いつかない。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?