Nushell:新時代的新型態Shell

Nu是什麼?

「NuShell: the shell where traditional Unix meets modern development, written in Rust」

Today, we're introducing a new shell, written in Rust. It draws inspiration from the classic Unix philosophy of #h/yellow pipelines, the #h/yellow structured data approach of PowerShell, functional programming, systems programming, and more.

Nu的中心思想

To Nu, everything is data.

Nushell可以使用winget安裝。

Nushell要解決什麼?

命令參數越來越多!

01|200x400

幾個範例

Filter

  • 大部份的Shell必須透過命令選項來完成需要的任務,Nullshell另闢蹊蹺以過濾器(Filter)來達成

例如:

ls任務 sh命令 Nushell命令
依日期排列 ls -l -t ls -l | sort-by modified
依日期排列
(最新在最後)
ls -ltr ls -l | sort-by modified | reverse

table

  • 輸出的結果不只是字串,而是結構化的表格(Table),資料也能轉向(行列互換)
sys
sys | pivot
sys | get cpu
ps | where mem > 1gb

設定

config
config | get startup

子運算式

  • Windows預設的設定檔:C:\Users\帳戶\AppData\Roaming\nushell\nu\config\config.toml
  • 可使用子運算式直接編輯:
notepad (config path)

「TOML」這個名字是「Tom's Obvious, Minimal Language(湯姆的淺顯的、極簡的語言)」的首字母略寫詞

─ 來源:TOML - 維基百科,自由的百科全書

開啟文字檔案

open covid19_global_cases_and_deaths.csv | sort-by country_en | nth 164

遇到的問題與解法

  • 在Nushell裡找不到需要的命令(如 git)
    • Nushell自動載入的路徑可以用echo $nu.path列出
    • 新增需要的路徑到PATH環境變數 (Windows操作)
  • 如何自訂執行Nullshell的預設alias?
    • 修改config.toml的 startup

優點

  • 類似SQL的語法,能更方便地操作檔案
  • 簡化命令,大幅降低命令選項
  • 能叫用原作業系統的命令或批次檔

相關連結

教學影片

##

您可能也會有興趣的類似文章

簡睿

服務於軟體業的資訊老兵。興趣廣泛,學習力佳,樂於分享所知所學。

您可能也會喜歡…

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *