-1

I am dealing with weird thing in my bash script and I can't understand what is happening here:

cd ~ && printf "CWD is $(echo $(pwd))\n" || printf "Critical err.\n" && exit 1;
printf "This should be printed, but it won't be.\n";

Bash 4.4.20.

1 Answers1

0

It should be

(cd ~ && printf "CWD is $(echo $(pwd))\n") || (printf "Critical err.\n" && exit 1)

Check this thread for more information.

|| and && operands inside if condition (i.e. between round parentheses) are logical operands (or/and)

Digvijay S
  • 2,665
  • 1
  • 9
  • 21