How to pass positional arguments to an interactive bash session

281 Views Asked by At

I wanted to start an interactive bash shell like this :

bash (...some options) 1 2 3

so that in the shell session, I have $1=1, ...

I didn't find any options to achieve the effect.

I tried this, thought it might work :

bash -c bash _ 1 2 3

but it didn't.

1

There are 1 best solutions below

7
On BEST ANSWER

From bash invoking bash:

-s

If this 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.

$ bash -s 1 2 3
$ echo $1
1 
$ exit
$