How to output return code in shell?

前端 未结 3 852
孤街浪徒
孤街浪徒 2021-02-05 02:50

I\'m trying to call a custom shell script through sh:

/bin/sh -c \'myscript.sh` >log.txt 2>&1 & echo $!

Output of th

相关标签:
3条回答
  • 2021-02-05 03:06
    echo $? >> /path/to/return_code
    

    $? has the return code of the last statement in bash.

    0 讨论(0)
  • 2021-02-05 03:19
    (/bin/sh -c "myscript.sh" >log.txt 2>&1 ; echo $? >somefile) & echo $!
    
    0 讨论(0)
  • 2021-02-05 03:26
    (
    /bin/sh -c 'myscript.sh` >log.txt 2>&1
    echo $? > some_file
    ) &
    
    0 讨论(0)
提交回复
热议问题