help-bash
[Top][All Lists]
Advanced

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

Re: detecting no arguments in $@


From: Andreas Kusalananda Kähäri
Subject: Re: detecting no arguments in $@
Date: Sun, 25 Jul 2021 14:22:20 +0200

On Sun, Jul 25, 2021 at 01:16:07PM +0200, 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.

The same code applies in this case.  Do you processing first and shift,
and replace the echo with the assignment of default values.  Each shift
decreases the value in $# until it reaches zero.


-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.



reply via email to

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