Fish的全称是Friendly Interactive Shell,是一种替代性的shell,马上就可以使用,并可以提供自动建议,用已安装的手册页就可编程完成,是一种功能齐全、可读的脚本语言,并支持彩色文字。
使用您的发行包管理器安装Fish:
apt install fish
使用fish
命令启动Fish shell :
root@localhost:~# fish
Welcome to fish, the friendly interactive shell
Fish的配置文件位于:~/.config/fish/config.fish
。您可以将命令或Fish函数写入此文件。fish_config
命令会在浏览器上加载自定义服务器:
Fish类似于其他shell:您先输入命令,后跟参数。
root@localhost ~# adduser Linode
Adding user `Linode' ...
Adding new group `Linode' (1001) ...
Adding new user `Linode' (1001) with group `Linode' ...
Creating home directory `/home/Linode' ...
但是,在Fish中,您要使用;
链接命令,而不是&&
:
root@localhost ~# mkdir FishDocs && cd FishDocs
Unsupported use of '&&'. In fish, please use 'COMMAND; and COMMAND'.
fish: mkdir FishDocs && cd FishDocs
^
Fish拥有全功能的脚本语言。您可以通过使用Fish编写的脚本来执行您使用脚本语言所做的任何事情,甚至可以使用一些更酷的东西,例如管理您的动画或戏剧。
Fish不支持Alias。Fish使用functions
。输入functions
,Fish将输出默认存在的函数列表:
root@localhost ~/.c/fish# functions
., N_, abbr, alias, cd, contains_seq, delete-or-exit, dirh, dirs,
down-or-search, eval, export, fish_config, fish_default_key_bindings,
fish_indent, fish_mode_prompt, fish_prompt, fish_sigtrap_handler,
fish_update_completions, fish_vi_cursor, fish_vi_key_bindings, fish_vi_mode,
funced, funcsave, grep, help, history, hostname, isatty, la, ll, ls, man, math,
mimedb, nextd, nextd-or-forward-word, open, popd, prevd, prevd-or-backward-word,
prompt_pwd, psub, pushd, seq, setenv, sgrep, trap, type, umask, up-or-search,
vared,
您可以使用functions name
语法开始编写自己的函数:
您可以使用Fish编写动态循环:
如果您是一个长期bash用户,您可能已经积累了大量的bash脚本、单行和配置,从而不愿意更改shell。Fish脚本的编写方式与其他脚本语言不同,但内置bash -c
命令将毫不犹豫地从Fish命令行运行bash脚本。
例如,如果您有一个会输出数字1-10的脚本:
for ((k=1; k<=10; ++k)); do echo $k; done
Expected keyword 'in', but instead found end of the statement
fish: for ((k=1; k<=10; ++k)); do echo $k; done
^
使用bash -c
,您可以将相同的脚本作为字符串运行,并在不退出Fish的情况下运行它。
学习Fish的最佳方法是使用它。Fish的设计遵循可发现性法则:
A program should be designed to make its features as easy as possible to discover for the user.
Rationale: A program whose features are discoverable turns a new user into an expert in a shorter span of time,
since the user will become an expert on the program simply by using it.
有关此主题的其他信息,您可能需要参考以下资源。
更多Linux教程请前往腾讯云+社区学习更多知识。
参考文献:《How to Install, Configure and Run the Fish Shell》
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。