[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Handling getopt for option without optional argument value
From: |
lisa-asket |
Subject: |
Handling getopt for option without optional argument value |
Date: |
Fri, 23 Jul 2021 22:08:53 +0200 (CEST) |
From: Lawrence Velázquez <vq@larryv.me>
To: lisa-asket@perso.be
Subject: Re: Handling getopt for option without optional argument value
Date: 23/07/2021 22:02:08 Europe/Paris
Cc: help-bash@gnu.org
Returning to the original question.
On Fri, Jul 23, 2021, at 10:22 AM, lisa-asket@perso.be wrote:
> I have the following bash function but when I call it with
>
> indus-printf-multiple -- "Test" "TNest"
>
> the variable $warn is not being set to 1.
>
> [...]
>
> ("-w"|"--warning")
> case "$2" in
> (+([[:digit:]]))
> local warn="$2"
> shift 2
> ;;
> (*)
> local warn="1"
> shift 2
> ;;
> esac
> declare -i local f=1
> ;;
It looks like you only set "warn" when a '-w' or '--warning' option
is present, but nothing you've shown us indicates that you're passing
such an option. So why should "warn" be set at all?
---
I have the idea of adding
local warn="1"
just before
case "$2" in
The change will result in
("-w"|"--warning")
local warn="1"
case "$2" in
(+([[:digit:]]))
local warn="$2"
shift 2
;;
(*)
local warn="1"
shift 2
;;
esac
Do you think it is better to use `declare` to set numeric values for `warn`?
declare -i local warn=1
- Handling getopt for option without optional argument value, (continued)
- Handling getopt for option without optional argument value, lisa-asket, 2021/07/23
- Re: Handling getopt for option without optional argument value, Dennis Williamson, 2021/07/23
- Handling getopt for option without optional argument value, lisa-asket, 2021/07/23
- Re: Handling getopt for option without optional argument value, Greg Wooledge, 2021/07/23
- Handling getopt for option without optional argument value, lisa-asket, 2021/07/23
- Re: Handling getopt for option without optional argument value, Chet Ramey, 2021/07/23
- Handling getopt for option without optional argument value, lisa-asket, 2021/07/23
- Re: Handling getopt for option without optional argument value, Greg Wooledge, 2021/07/23
- Handling getopt for option without optional argument value, lisa-asket, 2021/07/23
Re: Handling getopt for option without optional argument value, Lawrence Velázquez, 2021/07/23
- Handling getopt for option without optional argument value,
lisa-asket <=
Handling getopt for option without optional argument value, lisa-asket, 2021/07/23
- Re: Handling getopt for option without optional argument value, Greg Wooledge, 2021/07/23
- Handling getopt for option without optional argument value, lisa-asket, 2021/07/23
- Re: Handling getopt for option without optional argument value, Greg Wooledge, 2021/07/23
- Handling getopt for option without optional argument value, lisa-asket, 2021/07/23
- Re: Handling getopt for option without optional argument value, Greg Wooledge, 2021/07/23
- Re: Handling getopt for option without optional argument value, Dennis Williamson, 2021/07/23