~ $ bash -c 'echo "${@:0}"' a b 3 4
a b 3 4
On Sat, Jan 25, 2025, 2:42 PM sanjay kumar via <help-bash@gnu.org> wrote:
>https://www.gnu.org/software/bash/manual/bash.html#Invoking-Bash Says ->
>
> - -c
> -
> Read and execute commands from the first non-option
> argument command_string, then exit. If there are arguments after
> the command_string, the first argument is assigned to $0 and any remaining
> arguments are assigned to the positional parameters. The assignment
> to $0 sets the name of the shell, which is used in warning and error
> messages.
>
>
> So, bash -c is not behaving as mentioned in above document.
> RegardsSanjay
> On Saturday, January 25, 2025 at 02:49:13 PM GMT+5:30, Andreas Kähäri <
> andreas.kahari@abc.se> wrote:
>
> Je Sat, Jan 25, 2025 at 08:57:18AM +0000, sanjay kumar via Bug reports
> for the GNU Bourne Again SHell skribis:
> > > cat test.sh#!/bin/bashecho "argv[0] = ${0}"echo "argv[1] = ${1}"echo
> "argv[2] = ${2}"echo "count = ${#}"===================> bash -c ./test.sh
> abc defargv[0] = ./test.shargv[1] =argv[2] =count = 0===================>
> bash ./test.sh abc defargv[0] = ./test.shargv[1] = abcargv[2] = defcount =
> 2===================> bash -versionGNU bash, version 5.0.17(1)-release
> (x86_64-pc-linux-gnu)Copyright (C) 2019 Free Software Foundation,
> Inc.License GPLv3+: GNU GPL version 3 or later <
>http://gnu.org/licenses/gpl.html>
> > This is free software; you are free to change and redistribute it.There
> is NO WARRANTY, to the extent permitted by law.
> >
> > Looking for input.
> > Regards
> > Sanjay
> >
>
>
> When you execute
>
> bash -c ./test.sh abc def
>
> ... the bash shell that you invoke is snarted with argv[0] set to "abc"
> and argv[1] set to "def". The contents of the script is "./test.sh",
> and that command is invoked *without* any arguments.
>
> When you execute
>
> bash ./test.sh abc def
>
> ... the bash shell that you invoke is started with argv[1] set to "abc"
> and argv[2] set to "def". The argv[0] string is set to "./test.sh".
> The contents of the script is the contents of the file "./test.sh", and
> that command is invoked *with* the arguments "abc" and "def".
>
>
> --
> Andreas (Kusalananda) Kähäri
> Uppsala, Sweden
>
> .
>
>