我有一些困難,理解什麼是寫在我的Ubuntu的.bashrc
這是部分顯示在下面。 這是我不明白:瞭解這個.bashrc腳本(花括號,eval,...)
什麼是大括號的目的和
:
之後使用的-
/+
符號? (例如:$ {debian_chroot: - }和$ {debian_chroot:+($ debian_chroot)})eval
命令。下面的代碼片段如何工作。
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[email protected]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\[email protected]\h:\w\$ ' fi
謝謝。我不知道括號內的子殼。我也找到了這個鏈接來回答我的問題:http://wiki.bash-hackers.org/syntax/pe。不過我發現'$ {debian_chroot: - }'很奇怪。這不等於簡單的'$ debian_chroot'嗎? – Gradient 2013-05-07 06:10:19
@Gradient如果使用'set -u',則使用unset變量的嘗試將被視爲錯誤,而不是展開爲空字符串。 '$ {debian_chroot: - }'將明確地將未設置的變量擴展爲空字符串,從而避免該錯誤。 – chepner 2013-05-07 11:16:20