[Top][All Lists]

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

Re: BUG??

From: Greg Wooledge
Subject: Re: BUG??
Date: Thu, 29 Dec 2016 10:15:41 -0500
User-agent: Mutt/

On Thu, Dec 29, 2016 at 09:43:54PM +0700, PePa wrote:
> if (((q==1)) || [[ $r ]]) && grep -q $s $file
> then
>   echo "$s is in $file, and either q is 1 or r is not empty"
> fi
> I guess this works, but it spawns a subshell. Is there a better way?

What you're literally asking for should be done with command grouping
instead of a subshell:

if { ((q==1)) || [[ $r ]] ; } && grep -q "$s" "$file"; then ...

But my personal preference would be to rewrite it for readability:

if ((q==1)) || [[ $r ]]; then
  if grep -q "$s" "$file"; then

reply via email to

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