Great question! The difference in exit codes (${PIPESTATUS[@]}) between your two commands comes down to how pipelines and exit codes are handled in Bash, especially when tee is involved.
Why the Difference?
1. Pipeline Exit Codes
In Bash, a pipeline (commands chained with |) only returns the exit code of the last command in the pipeline by default. This is why your second command (without tee) only shows 0 1:
0: Exit code of ls_secret (success).
1: Exit code of sudo openconnect (failure).
2. ${PIPESTATUS[@]}
${PIPESTATUS[@]} is an array that stores the exit codes of all commands in the last pipeline. This is why your first command (with tee) shows 0 141 130:
0: Exit code of ls_secret (success).
141: Exit code of sudo openconnect (likely SIGPIPE, since tee closed its input early).
130: Exit code of tee (likely SIGINT or manual interruption).
Why 141 and 130?
141: This is 128 + 13 (SIGPIPE). It means openconnect tried to write to a pipe that was closed (likely because tee terminated early, e.g., due to a manual interrupt or error).
130: This is 128 + 2 (SIGINT). It means tee was interrupted (e.g., you pressed Ctrl+C).
Key Takeaways
Without tee, only the last command's exit code is shown (1 for openconnect).
With tee, ${PIPESTATUS[@]} reveals the exit codes of all commands in the pipeline, including tee itself.
The 141 and 130 suggest that either:
The VPN connection failed and tee was interrupted, or
You manually interrupted the process (Ctrl+C), causing tee to exit with 130 and openconnect to fail with 141 (SIGPIPE).
How to Debug Further
Check if openconnect is failing due to authentication or network issues.
Run openconnect without tee to see its direct output.
If you manually interrupted the process, the exit codes are expected.
Would you like help troubleshooting the VPN connection itself?
Feb 7, 2:39pm
This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.