前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >如何安装、配置和运行Fish Shell

如何安装、配置和运行Fish Shell

原创
作者头像
好烟
发布2018-08-15 11:45:03
2.7K0
发布2018-08-15 11:45:03
举报
如何安装,配置和运行Fish Shell
如何安装,配置和运行Fish Shell

Fish的全称是Friendly Interactive Shell,是一种替代性的shell,马上就可以使用,并可以提供自动建议,用已安装的手册页就可编程完成,是一种功能齐全、可读的脚本语言,并支持彩色文字。

安装Fish

使用您的发行包管理器安装Fish:

代码语言:txt
复制
apt install fish

使用fish命令启动Fish shell :

代码语言:txt
复制
root@localhost:~# fish
Welcome to fish, the friendly interactive shell

定制Fish

Fish的配置文件位于:~/.config/fish/config.fish。您可以将命令或Fish函数写入此文件。fish_config命令会在浏览器上加载自定义服务器:

自定义Fish Shell配置文件
自定义Fish Shell配置文件

关于Fish

Fish类似于其他shell:您先输入命令,后跟参数。

代码语言:txt
复制
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中,您要使用;链接命令,而不是&&

代码语言:txt
复制
root@localhost ~# mkdir FishDocs && cd FishDocs
Unsupported use of '&&'. In fish, please use 'COMMAND; and COMMAND'.
fish: mkdir FishDocs && cd FishDocs
                      ^

使用Fish

Fish拥有全功能的脚本语言。您可以通过使用Fish编写的脚本来执行您使用脚本语言所做的任何事情,甚至可以使用一些更酷的东西,例如管理您的动画或戏剧。

函数

Fish不支持Alias。Fish使用functions。输入functions,Fish将输出默认存在的函数列表:

代码语言:txt
复制
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类脚本
使用函数编写Fish类脚本

您可以使用Fish编写动态循环:

Fish Shell中的循环
Fish Shell中的循环

如果您是一个长期bash用户,您可能已经积累了大量的bash脚本、单行和配置,从而不愿意更改shell。Fish脚本的编写方式与其他脚本语言不同,但内置bash -c命令将毫不犹豫地从Fish命令行运行bash脚本。

例如,如果您有一个会输出数字1-10的脚本:

代码语言:txt
复制
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_script
fish_script

下一步

学习Fish的最佳方法是使用它。Fish的设计遵循可发现性法则

代码语言:txt
复制
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 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 安装Fish
    • 定制Fish
    • 关于Fish
    • 使用Fish
      • 函数
      • 下一步
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档