Shells
Shell提供了一個和操作系統交互的命令行接口。shell的主要功能就是從輸入取得命令然後去執行。FreeBSD內含了一些shell,包括:Bourne shell(sh)、 extended C shell(tcsh)。 其他shell也可在FreeBSD的Ports得到,例如:zsh和bash。
Shell的特點:
- 文件名補全
- 使用環境變量
Common Environment Variables
Variable Description
USER Current logged in user's name.
PATH Colon-separated list of directories to search for binaries.
DISPLAY Network name of the Xorg display to connect to, if available.
SHELL The current shell.
TERM The name of the user's type of terminal. Used to determine the capabilities of the terminal.
TERMCAP Database entry of the terminal escape codes to perform various terminal functions.
OSTYPE Type of operating system.
MACHTYPE The system's CPU architecture.
EDITOR The user's preferred text editor.
PAGER The user's preferred utility for viewing text one page at a time.
MANPATH Colon-separated list of directories to search for manual pages.
怎樣設置環境變量:不同的shell有不同的方法。
- 在tcsh和csh這樣的C-Style shell,使用setenv
設置環境變量
- 在sh和bash這樣的Bourne shell,使用, export
設置環境變量
例如:設置或改變EDITOR環境變量,將EDITOR設爲/usr/local/bin/vim.
在csh或tcsh下
setenv EDITOR /usr/local/bin/vim
在sh或bash下
export EDITOR="/usr/local/bin/vim"
命令行中在環境變量前加一個$字符,可以取得環境變量查看當前設置。
shell裏有許多特別的字符代表着特別的內容,我們把叫做meta-characters。最常用的就是*
字符,它可代表文件名的任何字符。爲了防止shell去分析這些特別字符, 我們可在它之前加一個\
字符去說明它只是普通字符。
改變Shell
改變Shell的最簡單方法是使用 chsh 命令。
- 執行 chsh 將根據EDITOR 環境變量進入到那個編輯器,假如沒有設定,就會進入vi編輯器。 請改變“Shell:”這行對應值。
- 可使用chsh 的-s選項, 這樣就能設置您的shell卻又不用編輯器。假如想把shell改爲bash:
chsh -s /usr/local/bin/bash
注意:新的shell必須在
/etc/shells
文件裏列出。 如果從ports裏安裝一個shell,應該默認自動添加到這個文件了。如果沒有添加,用下面的命令添加:echo "/usr/local/bin/bash" >> /etc/shells
,然後從新運行chsh
.
Shell高級技巧
Advanced Shell Techniques
- 重定向:
>
<
- 管道:
|