How can you tell if a Linux command has been executed successfully?

Tâm Tây

New member
How can you tell if a Linux command has been executed successfully?
Answer
Checking command Succeeded
  1. $ sudo apt update && sudo apt upgrade -y.
  2. $ echo $?
  3. $ echo $?
  4. #!/bin/bash. <command> if [ $? -eq 0 ]; then. echo OK. else. echo FAIL. fi.
  5. $ chmod +x demo.sh.
  6. $ ./ demo.sh.
  7. $ <command> && echo SUCCESS || echo FAIL.
  8. $ sudo apt update && echo SUCCESS || echo FAIL.
 

Tìm kiếm

Back
Top