help-bash
[Top][All Lists]
Advanced

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

Re: Organising conditions


From: Leonid Isaev (ifax)
Subject: Re: Organising conditions
Date: Mon, 2 Aug 2021 16:08:28 +0000
User-agent: Mutt/1.13.4 (2020-02-15)

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



reply via email to

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