How to pass arguments to /bin/bash? [closed] How to pass arguments to /bin/bash? [closed] unix unix

How to pass arguments to /bin/bash? [closed]


Drop the -c altogether. From the manpage:

bash [options] [file]…Bash  is  an  sh-compatible command language interpreter that executes commands read from the standard input or from a file.

Thus, you can execute your program via

bash myprogram myfile.ext

and myfile.ext will be the first positional parameter.

bash -l myprogram myfile.ext

will work as well, (but whether or not bash is invoked as a login shell seems tangential to this question.)


-c string     If  the  -c  option  is  present, then commands are read from    string.  If there are arguments after the  string,  they  are    assigned to the positional parameters, starting with $0.

You need to quote the command passed in as string so it's treated as a single argument for the -c option, which then gets executed normally with the argument following the command, i.e.

/bin/bash -c -l 'myprogram myfile.ext'