I was trying out different ways of emulating a boolean variable in bash. One method is:
readonly T=1 readonly F=0 ((T)) && echo "true" || echo "false" ((F)) && echo "true" || echo "false"
which prints true and false respectively. Then I had a brain cramp and typed:
! ((F)) && "yes"
expecting to see yes in the terminal. However, without the echo command, it went into an infinite loop printing y. Can someone explain what bash is doing here?
Advertisement
Answer
bash
didn’t go into an infinite loop. You’re running the yes
program, whose description is:
yes
– output a string repeatedly until killed
y
is the default string that it prints. The purpose is to pipe it to a command that’s going to ask lots of confirmation questions, so you can give the same answer to all of them. E.g.
yes | ./configure