1. 程式人生 > >Linux C/C++程式設計Shell命令大雜燴(1)

Linux C/C++程式設計Shell命令大雜燴(1)

1, 檢視發行版資訊

    cat /etc/issue

2, 檢視核心版本

   uname -r 檢視核心版本

   uname -p 檢視處理器型別32bit/64bit

   uname -n 檢視網路主機名(or hostname)

3,OpenJDK和JDK啥區別?

   Oracle JDK is based on the OpenJDK source code. In addition, it contains closed-source components. 也就是說,OpenJDK去掉了JDK中涉及一些版權問題的API和原始碼,功能比JDK少點。

4,父Shell、子Shell

  當在執行一個Shell Script時,父Shell會根據Script程式的第一行#!之後指定的Shell程式開啟一個子Shell環境,然後在子Shell中執行此Shell Script。一旦子Shell中的Script執行完畢,此子Shell隨即結束,回到父Shell中,不會影響父Shell原本的環境。子Shell環境擁有與父Shell相同的環境變數、標準輸入、輸出、錯誤等。

5, source命令作用?

      可以用help source檢視幫助文件。P.S. 點命令與source命令一樣,用法為. filename [arguments]

      source: source filename [arguments]


              Execute commands from a file in the current shell.

Read and execute commands from FILENAME in the current shell.  The entries in $PATH are used to find the directory containing FILENAME.  If any ARGUMENTS are supplied, they become the positional parameters when FILENAME is executed.

    Exit Status:

    Returns the status of the last command executed in FILENAME; fails if FILENAME cannot be read.

  檔案filename可以沒有執行許可權。

  在當前shell中執行和在子shell中執行的區別是,後者定義的變數和函式在執行結束後就消失了,而前者卻可以保留下來。因此,若我們修改了/etc/profile裡面的內容,如增加了環境變數,那麼如果要立即生效的話,就必須使用source命令或者點命令在當前shell中執行一下。

6, 環境變數

    (1)檢視所有環境變數:

      $ set

    (2)檢視某個環境變數:

      $ echo "$PATH"

   (3)設定環境變數:

export ANT_HOME=/path/to/ant/dir
export PATH=${PATH}:${ANT_HOME}/bin:${JAVA_HOME}/bin

 (4) 持久化環境變數的檔案:

     /etc/profile, 存放系統級環境變數的地方,對所有使用者有效。設定完之後需要重新登入才能生效。

     ~/.bashrc, 存放當前使用者環境變數的地方,只對當前使用者有效。設定完之後只需要重新啟動shell。

     當然,上面介紹的source命令可以立即生效。