الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

exit

End the shell or script with an exit status (0 = success, 1–255 = error); return does the same for a function.

المستوى
لينكس اليومي
المجموعة
الطرفية والمساعدة
يحتاج root
لا
الحزمة
bash (built-in)
يُسمّى أيضًا
return

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

Every command returns an exit status: 0 means success, any other number an error. $? holds the status of the last command. Scripts should end with exit 0 on success and a non-zero code for errors, so that other scripts, cron and systemd know what happened. exit in an interactive shell logs you out.

طريقة الكتابة

exit [N]
return [N]

الأجزاء الرئيسية

0
Success.
1
General error.
2
Wrong use (often from builtins).
126
Found, but cannot run.
127
Command not found.
128+N
Killed by signal N (130 = Ctrl+C, 137 = kill -9).

الخيارات 1

الأكثر استخدامًا

N
The exit status (0–255; default: the status of the last command).

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1End a script with success

    tail -1 backup.sh
    exit 0

    The caller sees 0.

  2. 2Exit with an error

    [ -d /backup ] || { echo "no backup folder" >&2; exit 1; }

    Message to stderr, code 1.

  3. 3See the status of the last command

    ls /nothing; echo $?
    ls: cannot access '/nothing': No such file or directory
    2

    ls uses 2 for this error.

  4. 4Command not found

    nosuchcommand; echo $?
    127

    127 = not found.

  5. 5Killed by Ctrl+C

    sleep 100
    ^C
    echo $?
    130

    128 + 2 (SIGINT).

  6. 6Return from a function

    isroot() { [ "$(id -u)" -eq 0 ] && return 0 || return 1; }; isroot && echo root || echo "not root"

    return = exit for functions.

  7. 7Use the status in if

    if grep -q lisa /etc/passwd; then echo found; fi

    if checks the exit status.

  8. 8Pass on the status of the last command

    cp a b; exit

    exit without N uses the status of cp.

  9. 9Leave a root shell

    exit

    Back to your own user.

  10. 10Exit codes in systemd

    systemctl status myapp | grep -i 'code='

    status=203/EXEC = the program could not be run.

رموز الخروج

N :: The given value (or the last command's status).