Checking the result from a command executed.
Hi,
How can I test the result of a command? In DOS, one can use errorlevel to check the return code and based in this, take further steps. I want to move a file from one directory to another with: Code:
mv /usr/test/myfile /usr/test/archive/myfile How can I do this? Thanks, J |
You've marked this as solved... can you provide any feedback incase others find it useful?
|
I may have been a bit quick on the draw on this one, but I though I had is solved. What I did was:
Code:
if [ -f filename ] J |
I didn't actually read your question, just that it was solved with no reply...
the equivalent to that awful ERRORLEVEL nonsense is the $? shell variable: Code:
# ls -l 1234 Code:
# basename /usr/bin/ls |
Aha, are you saying that invoking the echo $? immediately after a command will give me the return code of that command?
|
yup
|
That's exactly what I was looking for! Thanks bud, its working.
|
All times are GMT -5. The time now is 05:51 AM. |