linux shell程式,linuxshell

來源:互聯網
上載者:User

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]\$ '...

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.