help-bash
[Top][All Lists]
Advanced

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

Re: $@ giving --


From: Dennis Williamson
Subject: Re: $@ giving --
Date: Sun, 10 Oct 2021 21:15:40 -0500

On Sun, Oct 10, 2021, 7:42 PM Khan Smith <khansmith@mail.com> wrote:

>    I have the following code, but cannot understand why I get
>
>      $@:  -- First Sentence Second Sentence Third Sentence
>
>    when using
>
>    printm -n35 -l "First Sentence" "Second Sentence" "Third Sentence"
>
>    but get
>
>    $@: First Sentence Second Sentence Third Sentence
>
>    when using
>
>    printm -n35 -l1 "First Sentence" "Second Sentence" "Third Sentence"
>
>    Here is my bash function
>
>    printm ()
>    {
>     shortopts="Vuhv::H::w::e::"
>     shortopts="${shortopts}n::,l::,b,g,c,r,m,o"
>     longopts="version,usage,help,verbosity::"
>     longopts="${longopts},blu,grn,cyn,red,mgn,org"
>     longopts="${longopts},heading::,warning::,error::"
>
>     opts=$( getopt -o "$shortopts" -l "$longopts" -n "${0##*/}" -- "$@" )
>     eval "set -- ${opts}"
>     while (( $# > 0 )); do
>       case $1 in
>         ("-l")
>           case "$2" in
>             (+([[:digit:]]))
>           # matches -lNUM, optional argument value
>               nl="$2"; shift 2 ; echo "nl=$2" ;;
>             (*)
>               # matches -l, no argument value provided
>               nl=1 ; shift ; echo "nl=1" ;;
>           esac
>           ;;
>         ("--") shift ; break ;;
>         # ........................................................
>       esac
>     done
>
>     echo "nl: $nl"
>     echo "\$@: $@"
>
>    }
>

See my other message about getopt.

>


reply via email to

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