help-bash
[Top][All Lists]
Advanced

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

Re: detecting no arguments in $@


From: Alex fxmbsw7 Ratchev
Subject: Re: detecting no arguments in $@
Date: Sun, 25 Jul 2021 13:19:27 +0200

while [[ $1 ]] ; do
 .. $1 ..
 shift
done

On Sun, Jul 25, 2021 at 1:18 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> wrote:
>
> i=0
> while (( ++i <= $# )) ; do
>  arg=${!i}
> done
>
> or
>
> declare -n arg=args[i]
> args=( '' "$@" ) i=0
> while [[ -v args[++i] ]] ; do
>  printf 'arg: %s\n' "$arg"
> done
>
> On Sun, Jul 25, 2021 at 1:16 PM <dora-solomon@brusseler.com> wrote:
> >
> > From: Andreas Kusalananda Kähäri <andreas.kahari@abc.se>
> > To: dora-solomon@brusseler.com
> > Subject: Re: detecting no arguments in $@
> > Date: 25/07/2021 13:11:14 Europe/Paris
> > Cc: help-bash@gnu.org
> >
> > On Sun, Jul 25, 2021 at 01:07:53PM +0200, dora-solomon@brusseler.com wrote:
> > >
> > > Is it possible to figure out whether there are no arguments in $@ ?
> >
> >
> > If there are no positional parameters, i.e. if "$@" is empty, then "$#"
> > would be zero:
> >
> > if [ "$#" -eq 0 ]; then
> > echo 'there were no arguments given'
> > fi
> >
> >
> >
> > I was using shift  to get passed some options and if the last arguments did 
> > not
> >
> > contain anymore information such as directory names, I would set defaults.
> >
> >
> >
> >
> >
> >



reply via email to

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