linux shell程式,linuxshell
1、查看我們的Linux(centos6.5為例)有多少我們可以使用的shell:
[root@localhost bin]# cat /etc/shells /bin/sh/bin/bash/sbin/nologin/bin/dash/bin/tcsh/bin/csh
系統某些服務在運作過程中,會去檢查使用者能夠使用的shells,而這些shell的查詢就是由/etc/shells這個檔案。
2、當我們登入Linux系統的時候,系統就會給我一個shell來工作,而這個登入取得的shell就記錄在/etc/passwd這個檔案裡:
[root@localhost bin]# cat /etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologin...
3、shell的內部指令type,知道指令來自外部指令夥食內建在bash當中。
[root@localhost bin]# man cd[root@localhost bin]# type cdcd is a shell builtin[root@localhost bin]# type -t cdbuiltin #表示該指令為bash內建的指令功能[root@localhost bin]# type -a cdcd is a shell builtin[root@localhost bin]# type typetype is a shell builtin
[root@localhost bin]# type it ls
alias #表示該指令為命名別名所設定的名稱
[root@localhost bin]# type uname
uname is hashed (/bin/uname)
[root@localhost bin]# type -t uname
file #表示為外部指令
4、變數的取用 echo
[root@localhost bin]# echo $PATH/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin[root@localhost bin]# echo ${PATH}/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
變數的設定 = ,如果一個變數未設定,內容為空白
[root@localhost bin]# echo $myname[root@localhost bin]# myname=tian[root@localhost bin]# echo $mynametian
子程式,就是在目前這個shell的情況下,去啟用另一個新的shell,新的shell就是子程式。在一般狀態下,父程式的自訂變數無法在子程式內使用,但是通過export將變數變成環境變數,就能在子程式下應用了。
[root@localhost bin]# echo $nameyes[root@localhost bin]# bash #進入所謂的子程式[root@localhost bin]# echo $name[root@localhost bin]# exit #離開子程式exit[root@localhost bin]# export name[root@localhost bin]# bash[root@localhost bin]# echo $nameyes[root@localhost bin]# exit
變數的設定規則:
5、環境變數
env,environment的簡寫,列出所有的環境變數
[root@localhost /]# envHOSTNAME=localhost.localdomainSHELL=/bin/bashTERM=xtermHISTSIZE=1000USER=root...
set,觀察所有變數(包含環境變數和自訂變數)
[root@localhost /]# envBASH=/bin/bashBASH_VERSINFO=([0]="4" [1]="1" [2]="2" [3]="1" [4]="release" [5]="i386-redhat-linux-gnu")BASH_VERSION='4.1.2(1)-release'HISTFILE=/root/.bash_historyHISTFILESIZE=1000HISTSIZE=1000HOSTTYPE=i386OLDPWD=/OSTYPE=linux-gnuPPID=5200PS1='[\u@\h \W]\$ '...