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 15:40:24 +0000

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

> On Mon, Aug 02, 2021 at 02:46:46PM +0000, hancooper wrote:
>
> > Then doing
> > if [[ -d "$dir" && ! $list_raw ]]; then
> > or
> > if [[ -d "$dir" ]] && [[ ! $list_raw ]]; then
> > is simply dependent on preference, rather than functionality?
>
> If you are asking a generic question, then you should consider having more 
> than
> two tests. In this case, the former if..then stanza is better because it 
> allows
> grouping without subshells. For instance:

It is a generic question.  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
      for fde in "${flist[@]}"; do
        [[ $fde == $file ]] && file_redundant=true
      done
      [[ (-f "$file") && (! $file_redundant) ]] && flist+=("$file")
    done

Nevertheless, I am still ending up with an empty flist.

${flist[*]} does not give me anything, whilst ${#flist[@]} is giving me 1.




> -----8<-----
> if [[ (-d "$dir" && -z "$new_dir") || (! "$list_raw") ]]; then
> ...
> fi
> ----->8-----
>
> --
>
> Leonid Isaev





reply via email to

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