流編輯器 - 環境



本章描述如何在您的 GNU/Linux 系統上設定 SED 環境。

使用包管理器安裝

通常,大多數 GNU/Linux 發行版預設都提供 SED。使用which命令可以確定它是否已安裝在您的系統上。如果沒有,則可以使用以下方法在基於 Debian 的 GNU/Linux 上使用apt包管理器安裝 SED:

[jerry]$ sudo apt-get install sed 

安裝後,確保可以透過命令列訪問 SED。

[jerry]$ sed --version

執行上述程式碼後,您將得到以下結果

sed (GNU sed) 4.2.2 
Copyright (C) 2012 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later . 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law.  
Written by Jay Fenlason, Tom Lord, Ken Pizzini, 
and Paolo Bonzini. 
GNU sed home page: . 
General help using GNU software: . 
E-mail bug reports to: . 
Be sure to include the word "sed" somewhere in the "Subject:" field.

類似地,要在基於 RPM 的 GNU/Linux 上安裝 SED,請使用 yum 包管理器,如下所示:

[root]# yum -y install sed

安裝後,確保可以透過命令列訪問 SED。

[root]# sed --version

執行上述程式碼後,您將得到以下結果

GNU sed version 4.2.1 
Copyright (C) 2009 Free Software Foundation, Inc. 
This is free software; see the source for copying conditions.  There is NO 
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, 
to the extent permitted by law.  
GNU sed home page: . 
General help using GNU software: . 
E-mail bug reports to: . 
Be sure to include the word "sed" somewhere in the "Subject:" field.

從原始碼安裝

由於 GNU SED 是 GNU 專案的一部分,其原始碼可以免費下載。我們已經瞭解瞭如何使用包管理器安裝 SED。現在讓我們瞭解如何從其原始碼安裝 SED。

以下安裝適用於任何 GNU/Linux 軟體,以及大多數其他免費程式。以下是安裝步驟:

  • 從可靠的來源下載原始碼。命令列工具wget可以實現此目的。

  • [jerry]$ wget ftp://ftp.gnu.org/gnu/sed/sed-4.2.2.tar.bz2
    
  • 解壓縮並提取下載的原始碼。

  • [jerry]$ tar xvf sed-4.2.2.tar.bz2 
    
  • 進入目錄並執行 configure。

  • [jerry]$ ./configure 
    
  • 成功完成後,configure將生成 Makefile。要編譯原始碼,請發出make命令。

  • [jerry]$ make
    
  • 您可以執行測試套件以確保構建乾淨。這是一個可選步驟。

  • [jerry]$ make check 
    
  • 最後,安裝 SED 實用程式。確保您擁有超級使用者許可權。

  • [jerry]$ sudo make install 
    

就是這樣!您已成功編譯並安裝 SED。透過執行以下sed命令進行驗證:

[jerry]$ sed --version

執行上述程式碼後,您將得到以下結果

sed (GNU sed) 4.2.2 
Copyright (C) 2012 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later . 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law.  
Written by Jay Fenlason, Tom Lord, Ken Pizzini, 
and Paolo Bonzini. 
GNU sed home page: . 
General help using GNU software: . 
E-mail bug reports to: . 
Be sure to include the word "sed" somewhere in the "Subject:" field.
廣告