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

Reply via email to