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

set

Turn shell options on or off (like -x trace, -e stop on error), set the positional parameters, or list all variables.

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

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

ماذا يفعل

set -OPTION turns an option on, set +OPTION turns it off. In scripts the most used line is set -euo pipefail (stop on errors, error on unset variables, fail on broken pipes). set -- a b c sets $1 $2 $3. Without arguments, set prints all shell variables and functions.

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

set [-abefhkmnptuvxBCEHPT] [-o OPTION] [--] [ARGUMENT]...

الخيارات 23

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

-e, -o errexit
Exit when a command fails.
-u, -o nounset
Error when an unset variable is used.
-x, -o xtrace
Print commands before running them (trace).
-o pipefail
A pipe fails if any command in it fails.
-v, -o verbose
Print lines as they are read.
-n, -o noexec
Read commands but do not run them.
-f, -o noglob
No wildcard expansion.
-C, -o noclobber
> does not overwrite files (use >| to force).
-a, -o allexport
Export all new variables.
-b, -o notify
Report finished jobs at once.
-h, -o hashall
Remember command locations.
-k, -o keyword
All assignments go to the environment.
-m, -o monitor
Job control.
-p, -o privileged
Privileged mode.
-t, -o onecmd
Exit after one command.
-B, -o braceexpand
Brace expansion (on by default).
-E, -o errtrace
ERR traps in functions.
-H, -o histexpand
! history expansion.
-P, -o physical
No symlinks for cd and pwd.
-T, -o functrace
DEBUG/RETURN traps in functions.
-o vi, -o emacs
Editing mode of the command line.
-o
List all options and their state.
--
Set the positional parameters (or clear them).

أمثلة 10

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

  1. 1Strict mode for scripts

    head -2 /usr/local/bin/backup.sh
    #!/bin/bash
    set -euo pipefail

    Many hidden errors become visible.

  2. 2Trace part of a script

    set -x; cp a b; set +x
    + cp a b

    Only these lines are traced.

  3. 3Stop on errors

    bash -c 'set -e; false; echo "not reached"'

    The script ends at false.

  4. 4Unset variable error

    bash -c 'set -u; echo "$TYPO"'
    bash: line 1: TYPO: unbound variable

    Catches typos like rm -rf "$DIR/" with an empty DIR.

  5. 5Pipe failures

    bash -c 'set -o pipefail; false | true; echo $?'
    1

    Without pipefail the result would be 0.

  6. 6Do not overwrite files

    set -C; echo x > existing.txt
    bash: existing.txt: cannot overwrite existing file

    Protects against a wrong >.

  7. 7vi mode on the command line

    set -o vi

    Esc, then vi keys to edit.

  8. 8Show all options

    set -o | head

    on/off for each.

  9. 9Set positional parameters

    set -- one two three; echo "$2 / $#"
    two / 3

    Useful in tests and functions.

  10. 10List variables and functions

    set | grep ^HIST

    All HIST variables.

رموز الخروج

0Done.
1Wrong option.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man set