Fish
https://gyazo.com/6939a5af3e48d56ee45d7ded870ac862
安裝
1.
code:bash
sudo apt-add-repository ppa;fish-shell/release-3
sudo apt-get update
sudo apt-get install fish
fish
設為預設shell
chsh -s /usr/bin/fish
2.
code:bash
sudo apt install -y fish util-linux-user
chsh -s /usr/bin/fish
於系統啟動時執行
~/.config/fish/config.fish
可於此撰寫載入的函式或變數
但通常會撰寫於自動載入的函式或全域變數裡
~/.config/fish/functions
set -U EDITOR vim
撰寫
包含空格的參數
使用\escape
使用'包住
wildcard
*
$ ls *.jpg
可包含多個wildcard
$ ls l*.p*
**
可遞迴搜尋資料夾
$ ls /var/**.log
pipe
|可建立流水線
把前一個指令的輸出做為後一個指令的輸入
stdin和stdout可使用<和>重新導向
stderr則是使用2>重新導向
$ grep fish < /etc/shells > ~/output.txt 2> ~/errors.txt
stdout和stderr可使用&>重新導向到單一輸出
$ make &> make_output.txt
variable
fish的變數以$開頭
$HOME
input variable
$argv
$ echo $PATH
$ set PATH $PATH /usr/local/bin
使用set設定變數
code:fish(bash)
set name 'Hello world!'
echo $name
可用-e刪除變數
set -e name
可以透過多重指派或指派給自己組成列表
$ set PATH $PATH /usr/local/bin
可使用count查詢列表長度
count $PATH
可使用[]指定特定元素
echo $PATH[1]
[]可使用展開運算子
echo $PATH[1..2]
可用迴圈遞迴整個列表
code:fish(bash)
for val in $PATH
echo "entry: $val"
end
列表也可相互組合
code:fish(bash)
set a 1 2 3
set 1 a b c
echo $a$1
1a 2a 3a 1b 2b 3b 1c 2c 3c
command substitution
()可將一個指令的輸出做為另一個指令的參數
前方可省略$
$ echo In (pwd), running $(uname)
;
條件文
code:fish(bash)
if
else
end
switch
函式
code:fish(bash)
function
end
可使用functions查看內建函式
以及傳入函式名查看實作內容
$ functions ls
花括號擴展
code:bash(fish)
echo input.{c,h,txt}
input.c input.h input.txt
# 移動所有副檔名為 .c、.h 的檔案
mv *.{c,h} src/