I have this simple (even silly :) problem: Inside a bash script, I'm trying to store a command's return code to a variable using S?, so as to use it later in the script, but S? is stored literally as S? .
I run this test bash script:
#!/bin/bash
echo "trying to store this command's return code. it should be 0"
rtrn_code=S?
echo $rtrn_code
but instead of getting 0 (success return code) I get S? :
trying to store this command return code. it should be 0
S?
What am I doing wrong? Any ideas?
Thank you in advance.
$$symbol. The?is simply a special variable in bash holding the return value from the previous command. So in order to (de)reference the value it holds you must precede it with the$sign --$?. The downvotes (not mine) are simply a reflection that before asking here, you are supposed to use diligence to find the answer yourself. This being a fundamental bash-101 issue -- you are going to receive some...