开发运维小工具:import也可以是个shell命令



在golang语言中,可以用import <包的网上路径> 来导入另一个远程依赖包。这样就可以本地使用远程包提供的函数。

受此启发,shell阵营也新增了这么一个import工具(https://import.pw/)。先来看下怎么使用吧。


使用方法:

#!/usr/bin/env import

# The URL is downloaded once, cached forever, and then sourced
import "https://git.io/fAWiz"

add 20 22
# 42


import会将https://git.io/fAWiz提供的包,下载并缓存住以备后面可以使用。

https://git.io/fAWiz的提供了一个函数名叫add,内容如下:

add() {
  expr "$1" + "$2"
}

除了bash,import文件工具还支持zsh/ksh/ash脚本语言。


安装方法:

使用import工具,需要先安装它

curl -sfLS https://import.pw > /usr/local/bin/import
chmod +x /usr/local/bin/import

胜象大百科