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

bash

The Bourne Again Shell: the default command shell of RHEL, and the program that runs shell scripts.

المستوى
امتحان RHCSA
المجموعة
الطرفية والمساعدة
يحتاج root
لا
الحزمة
bash

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

ماذا يفعل

bash reads commands from the terminal or from a script. A login shell reads /etc/profile, /etc/profile.d/*.sh and ~/.bash_profile; an interactive shell reads ~/.bashrc (and /etc/bashrc). bash -n script checks the syntax; bash -x script shows each command as it runs.

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

bash [OPTION]... [-c COMMAND | SCRIPT [ARGUMENT]...]

الخيارات 20

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

-c STRING
Run the commands in STRING.
-n
Read but do not run (syntax check).
-x
Print each command before running it (trace).
-v
Print each line as it is read.
-e
Exit at the first failing command.
-u
Error on unset variables.
-i
Interactive shell.
-l, --login
Act as a login shell (read the profile files).
-s
Read commands from standard input.
-r, --restricted
Restricted shell (no cd, no PATH changes …).
-D, --dump-strings
List translatable strings.
-O OPTION, +O OPTION
Set or unset a shopt option.
-o OPTION
Set an option like set -o.
--noprofile
Do not read the profile files.
--norc
Do not read ~/.bashrc.
--rcfile FILE
Read FILE instead of ~/.bashrc.
--posix
POSIX mode.
--debugger
Debugger profile.
--help
Show help.
--version
Show the version.

أمثلة 10

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

  1. 1Run a script

    bash backup.sh

    Works even without the x permission.

  2. 2Check the syntax

    bash -n backup.sh

    No output = no syntax error.

  3. 3Trace a script

    bash -x backup.sh 2>&1 | less

    Each command with filled-in values (lines start with +).

  4. 4Run one command line

    bash -c 'for i in 1 2 3; do echo $i; done'

    Useful with sudo, ssh and find -exec.

  5. 5A clean shell for tests

    bash --noprofile --norc

    Without your aliases and settings.

  6. 6Start a login shell

    bash -l

    Reads the profile files again (after changes).

  7. 7Which shell am I using?

    echo $SHELL; ps -p $$ -o comm=
    /bin/bash
    bash

    $SHELL is the login shell; ps shows the running one.

  8. 8Version (for script features)

    bash --version | head -1

    RHEL 10 has bash 5.2.

  9. 9Run a script with sudo and a heredoc

    sudo bash -s <<'EOF2'
    dnf -y upgrade
    systemctl restart httpd
    EOF2

    Several root commands in one go.

  10. 10Find scripts with strict settings

    grep -l 'set -euo pipefail' /usr/local/bin/*.sh

    Scripts that stop on errors.

الملفات

/etc/profile, /etc/profile.d/
Login settings for all users.
/etc/bashrc
Interactive settings for all users.
~/.bash_profile, ~/.bashrc
Personal settings.
~/.bash_history
Command history.

رموز الخروج

0 :: The script or command worked. 1-255 :: The exit status of the last command (2 = wrong use of a builtin, 126 = cannot run, 127 = not found).

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

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

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