help-bash
[Top][All Lists]
Advanced

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

Re: code not working ..


From: Greg Wooledge
Subject: Re: code not working ..
Date: Tue, 10 Sep 2024 19:14:03 -0400

On Wed, Sep 11, 2024 at 00:25:15 +0200, alex xmb sw ratchev wrote:
> i got in a script
> 
> ca=( "$@" )
>   checkarg() {                                                           !
> (( $# )) &&
> return 1
> local IFS=$'\xff \t\n' i a
> i=${IFS:0:1}
>  for a ; do
> [[ ${ca[*]//"$i"/'^^'} == @(#|"$i")@("$a")@(%|"$i") ]] ||
> return 1
>  done
> return 0
>   }
> 
> checkarg 1 &&
> exit

This function should return 1 immediately if you give it any arguments.
The function you pasted into this email is not the same one you're running.

> -- the script runs , but at checkarg 1 ( 1 is first and only arg to script
> ) fails at the [[ , not returning 0
> 
> -x says
> 
> + ca=("$@")
> + checkarg 1
> + ((  1  ))
> + local 'IFS=�
> ' i a
> + i=$'\377'
> + for a in "$@"
> + [[ 1 == @(#|\�)@(\1)@(%|\�) ]]
> + return 1
> 
> but why doesnt it return null ?

Assuming that the function you executed actually has

    (( $# )) || return 1

instead of

    (( $# )) && return 1

you are trying to match the string "1" against a pattern whose first
character must be "#" or $'\xff', and "1" is not either of these.  So
it doesn't match the pattern.

What happens from there is anyone's guess, because you aren't showing
us the right function.

> its supposed to do : ( argslist , with arg '1' as check )
> args list , flat , xff separator , with inside occurrence of xff
> ==
> @(either beginning of whole || or xff )

Why do you believe that the "#" character is "beginning of whole"?
It's not.

Glob patterns are always anchored, similar to a regex with ^ at the
start and $ at the end.  You don't need to put # in to serve as an
anchor.  If you put # there, it's just a plain, literal character
that has to be matched.

> is xff 377 ?

\xff is \0377.  They are both encodings of a byte where every bit is 1.



reply via email to

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