help-bash
[Top][All Lists]
Advanced

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

Re: Organising conditions


From: Greg Wooledge
Subject: Re: Organising conditions
Date: Mon, 2 Aug 2021 10:56:33 -0400

On Mon, Aug 02, 2021 at 02:43:36PM +0000, hancooper wrote:
> Do (-d "$dir") and (! $list_raw)  also fork a subshell?

Outside of the [[ ]] command, yes.

Inside of the [[ ]] command, no.

> 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.

It's bad.  It's a massive performance hit for no reason.


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?

Yes.  Also, the one with parentheses INSIDE the [[ ]] command is fine
as well.

Just don't put parentheses OUTSIDE.



reply via email to

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