help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -c option not working as expected


From: Andreas Kähäri
Subject: Re: -c option not working as expected
Date: Sat, 25 Jan 2025 10:19:08 +0100

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

.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]