help-bash
[Top][All Lists]
Advanced

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

Re: Organising conditions


From: hancooper
Subject: Re: Organising conditions
Date: Mon, 02 Aug 2021 17:30:29 +0000

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Monday, August 2, 2021 4:08 PM, Leonid Isaev (ifax) <leonid.isaev@ifax.com> 
wrote:

> On Mon, Aug 02, 2021 at 03:40:24PM +0000, hancooper wrote:
>
> > I got into it as am populating an array of files, checking if they exist or
> > are redundant.
> >
> >     for file in "$@"; do
> >       file_redundant=false
> >
>
> $file_redundant contains a string "false". It is NOT a boolean variable.
>
> >       for fde in "${flist[@]}"; do
> >         [[ $fde == $file ]] && file_redundant=true
> >
>
> If you use $file without quotes, it is considered a pattern. To match $fde and
> $file as strings, you should quote $file, i.e. [[ "$fde" == "$file" ]].
>
> >       done
> >       [[ (-f "$file") && (! $file_redundant) ]] && flist+=("$file")
> >
>
> (! $file_redundant) is always false here because $file_redundant is 
> initialized
> to a string ("false" or "true"). Try ("$file_redundant" == "true") instead.
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Leonid Isaev

I want to write a bash function to display keys and values of an associative 
array.
Have done as follows.  Is it simply a matter of using $1 and $2 for tho 
associative
array name and title?

keyv ()
{
  echo "$title"
  for key in "${!aa[@]}"; do
    echo "Key:   ${key}"
    echo "Value: ${aa[$key]}"
  done
}






reply via email to

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