Artificial intelligent assistant

Piping 'false' does not give non-zero result code I understand these: true; echo "$?" # 0 false; echo "$?" # 1 true | echo "$?" # 0 But not this: false | echo "$?" # 0 ...Why doesn't it print `1`? And how could I force a failure in a pipe, and get `1` thereafter?

The result of both `true | echo "$?"` and `false | echo "$?"` is misleading. The content of `"$?"` will be set _before_ piping the command `false` to the command `echo`.

To execute these lines, bash sets up a pipeline of commands. The pipeline is setup, then the commands started in parallel. So in your example:


true; echo "$?" # 0
false; echo "$?" # 1
true | echo "$?" # 0


is the same as:


true
echo "$?" # 0
false
echo "$?" # 1
echo "$?" # 0


`true` is not executed before `echo $?` it is executed at the same time.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 2440011ff1b303557549bca5a8ade5ca