هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
A variable you set in Bash (NAME=value) is only known to that shell. export NAME puts it in the environment, so every program and script started from this shell gets a copy.
unset NAME removes a variable (or a function with unset -f).
To keep a variable for future logins, write the export line in ~/.bashrc (for you) or in a file in /etc/profile.d/ (for everybody).
طريقة الكتابة
export [-fn] [NAME[=VALUE] ...]
export -p
unset [-fv] NAME [NAME ...]الخيارات 6
الأكثر استخدامًا
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 11
$ مستخدم عادي# بصلاحية root (أو مع sudo)
1Set and export a variable in one step
export APP_ENV=staging bash -c 'echo $APP_ENV' stagingThe new shell (a child program) sees the value.
2Add a folder to the PATH
export PATH="$PATH:$HOME/bin"Keep the old PATH and add your folder at the end. Put the line in
~/.bashrcto keep it.3Keep a variable for every login
echo 'export EDITOR=vim' >> ~/.bashrcTools like
crontab -e,visudoandgituse the EDITOR variable.4Set a variable for all users
echo 'export HISTTIMEFORMAT="%F %T "' > /etc/profile.d/history-time.shEvery user gets times in
historyafter the next login.5Use a proxy for the tools in this shell
export http_proxy=http://proxy.example.com:3128 https_proxy=http://proxy.example.com:31286Remove a variable
unset http_proxy https_proxyTurns the proxy off for this shell again.
7List the exported variables
export -p | headSame information as
env, but in a form you could paste back into a shell.8Stop exporting a variable but keep it
export -n APP_ENVThe value stays in this shell; new programs no longer get it.
9Export a function to a child script
log() { echo "$(date +%T) $*"; } export -f log bash -c 'log "hello from child"'Child Bash processes can use the function.
10Pass settings to a container or a tool without editing files
export KUBECONFIG=$HOME/.kube/staging.yaml kubectl get nodesOne variable switches the cluster for this terminal only.
11Remove a secret from the shell after use
export DB_PASSWORD='s3cret'; ./migrate.sh; unset DB_PASSWORDShorter life for the secret in the shell. Better: let the tool read it from a protected file.
لا يوجد شيء يطابق هذا الفلتر.
انتبه
- No spaces around
=:export A = 1is wrong. - A child can never change the variables of its parent. A script that exports a variable does not change your shell, unless you run it with
source. unset PATHbreaks the shell until you set PATH again.
الملفات
~/.bashrc- Your exported variables for every shell.
/etc/profile.d/*.sh- Exported variables for all users.
نصائح للحفظ
- Set:
NAME=value. Pass on:export NAME. Both:export NAME=value. Remove:unset NAME.