help-bash
[Top][All Lists]
Advanced

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

$@ giving --


From: Khan Smith
Subject: $@ giving --
Date: Mon, 11 Oct 2021 00:12:39 +0200

   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 "\$@: $@"

   }


reply via email to

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