[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 14:43:36 +0000 |
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Monday, August 2, 2021 2:23 PM, Greg Wooledge <greg@wooledge.org> wrote:
> On Mon, Aug 02, 2021 at 01:52:00PM +0000, hancooper via wrote:
>
> > I am using some conditions and would like some assessments on the
> > following. For instance, are
> > they all valid?
>
> > if [[ -d "$dir" && ! $list_raw ]]; then
> > tmpfile=$oldfile
> > fi
>
> > if [[ -d "$dir" ]] && [[ ! $list_raw ]]; then
> > tmpfile=$oldfile
> > fi
>
> > if [[ (-d "$dir") && (! $list_raw) ]]; then
> > tmpfile=$oldfile
> > fi
>
> Those three are fine. Pick whichever one you like.
>
> > if ([[ -d "$dir" && ! $list_raw ]]); then
> > tmpfile=$oldfile
> > fi
>
> This one is not advised. The parentheses create a subshell, which forks
> a child shell process. This is simply unnecessary. It's not even adding
> to readability.
Do (-d "$dir") and (! $list_raw) also fork a subshell? I would use it for
readability.
Is it fine to fork subshells when using conditions as I do? I do not know much
about
whether forking of subshells in bash is good, bad, or whatever.
- Organising conditions, hancooper, 2021/08/02
- Re: Organising conditions, Greg Wooledge, 2021/08/02
- Re: Organising conditions,
hancooper <=
- Re: Organising conditions, hancooper, 2021/08/02
- Re: Organising conditions, Leonid Isaev (ifax), 2021/08/02
- Re: Organising conditions, hancooper, 2021/08/02
- Re: Organising conditions, Greg Wooledge, 2021/08/02
- Re: Organising conditions, hancooper, 2021/08/02
- Re: Organising conditions, Greg Wooledge, 2021/08/02
- Re: Organising conditions, hancooper, 2021/08/02
- Re: Organising conditions, Greg Wooledge, 2021/08/02
- Re: Organising conditions, Leonid Isaev (ifax), 2021/08/02
- Re: Organising conditions, hancooper, 2021/08/02