curlでダウンロードしたスクリプトをそのままbash(またはsh)にパイプで渡すインストール方法、増えましたね。
ところで、このスクリプトに引数を渡すにはどうすれば?と思ったりします。
bashの場合は-sオプションを使えばよいみたいです。
-s If the -s option is present, or if no arguments remain after option processing, then commands
are read from the standard input. This option allows the positional parameters to be set when
invoking an interactive shell or when reading input through a pipe.
Ubuntu Manpage: bash - GNU Bourne-Again SHell
これはbashを対話型やパイプ経由でスクリプトを実行した時に、位置引数を設定できるオプションです。
$ curl ... | bash -s [引数]
のように使うとよいでしょう。
たとえばClaude Codeであれば以下のように指定すると、指定したバージョンをインストールできます。
$ curl -fsSL https://claude.ai/install.sh | bash -s 2.0.76
対話型の場合は、こういう動きになります。
$ bash -s arg1 $ echo $1 arg1
dashだとどうなんでしょう。試してみます。
script.sh
echo "\$1: $1"
よさそうです。
$ cat script.sh | dash -s test $1: test
確認環境は、Ubuntu Linux 24.04 LTSです。
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 24.04.3 LTS Release: 24.04 Codename: noble $ uname -srvmpio Linux 6.8.0-90-generic #91-Ubuntu SMP PREEMPT_DYNAMIC Tue Nov 18 14:14:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux