0

The command bellow works well in bash:

find . -depth -name Chart.yaml -exec sh -c 'f="{}"; if [[ ($f =~ ./api-*) && !($f =~ ./api-pnp-*) && !($f =~ ./api-edb-*) ]]; then tmpifs=`echo $IFS`; verstr=`grep version $f`; IFS=" "; read -r -a strarr5 <<< $verstr; if [[ $strarr5[2] =~ ([0-9]+).([0-9]+)* ]]; then IFS=“.” read -r -A verno <<< $strarr5[2]; Minornew=`echo $verno[2]+1 |bc`; Minorold=`echo $verno[2]`; sed -i '.bakrohit' "s/$Minorold/$Minornew/g" $f; echo $f $Minorold $Minornew; fi; fi;' \;

But the same command in zsh, escape the extra if conditions "!($f =~ ./api-pnp-*) && !($f =~ ./api-edb-*)"

find . -depth -name Chart.yaml -exec zsh -c 'f="{}"; if [[ ($f =~ ./api-*) && !($f =~ ./api-pnp-*) && !($f =~ ./api-edb-*) ]]; then tmpifs=`echo $IFS`; verstr=`grep version $f`; IFS=" "; read -r -A strarr5 <<< $verstr; if [[ $strarr5[2] =~ ([0-9]+).([0-9]+)* ]]; then IFS=“.” read -r -A verno <<< $strarr5[2]; Minornew=`echo $verno[2]+1 |bc`; Minorold=`echo $verno[2]`; sed -i '.bakrohit' "s/$Minorold/$Minornew/g" $f; echo $f $Minorold $Minornew; fi; fi;' \;

api-* includes api-edb-* and api-pnp-*, but i want to exclude those.

How to put multiple if condition together in zsh.

  • `var=$(echo something)` is wrong, **especially** if you [fail to quote your variable](https://unix.stackexchange.com/q/171346/4667). Just use `var=something` – glenn jackman Nov 02 '20 at 18:28
  • `$strarr5[2]` is wrong in bash, use `${strarr5[2]}` -- `$strarr5[2]` is the concatenation of `${strarr5[0]}` and `"[2]"` – glenn jackman Nov 02 '20 at 18:31
  • You're allowed to put newlines in a quoted string. In my view, this command is unmaintainable. That script is complicated enough that you should be doing `find ... -exec bash script.bash '{}' ';'` and in the script, `f="$1"` – glenn jackman Nov 02 '20 at 18:35
  • Compare `zsh -xc '[[ !( $0 =~ x ) ]]' x` to `zsh -xc '[[ ! ( $0 =~ x ) ]]' x` (just one space but different results). Also, it looks like you are using regex operator `=~` with shell pattern `./api-*` (although that is a valid regex, it has different meaning than what was likely intended). – rowboat Nov 03 '20 at 05:18

0 Answers0