help-bash
[Top][All Lists]
Advanced

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

Parsing options in the form "-C8"


From: irenezerafa
Subject: Parsing options in the form "-C8"
Date: Tue, 16 Nov 2021 23:29:19 +0000

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Tuesday, November 16th, 2021 at 9:35 PM, Chet Ramey <chet.ramey@case.edu> 
wrote:

> On 11/16/21 4:31 PM, irenezerafa wrote:
>
> > > So, given your original question, how does either of these constructs
> > >
> > > help you handle -C8?
> >
> > I could do with ("-C") which would have to be included after a ("-C=")
>
> Hey, look at that.

This is my implementation

 local cnt=1
 while (( $# > 0 )); do
   case $1 in
    ("-C"|"--count")
      cnt=1
      [[ "$2" =~ ^[0-9]+$ ]] && { cnt="$2" ; shift ; shift ; }
      bingly-bong "$cnt"
      return 0
      ;;
    ("-C="*|"--count="*)
      cnt="${1#*=}"
      bingly-bong "$cnt"
      return 0
      ;;
    ("-C"*)
      usg="${1#*C}"
      bingly-bong "$cnt"
      return 0
      ;;
   esac
 done

Any advice on a neater implementation?  And ideas on whether I missed something?




reply via email to

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