set -e表示一旦脚本中有命令的返回值为非0,则脚本立即退出,后续命令不再执行;
set -o pipefail表示在管道连接的命令序列中,只要有任何一个命令返回非0值,则整个管道返回非0值,即使最后一个命令返回0.
---------------------------------------------------------------------------------------------------------------------------------------------------------------
tput rev # reverse 命令行背景反转
tput bold # bold 字体加粗
echo 'Please provide a path to a SSH private key to access Manta.'
tput sgr0 # clear 回归原状
---------------------------------------------------------------------------------------------------------------
if [ -z "$1" ]; then 是空
if [ ! -f "$1" ]; then 文件不存在
---------------------------------------------------------------------------------------------------------------
$ command -v foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; } $ type foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; } $ hash foo 2>/dev/null || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
判断命令是否存在
------------------------------------------------------------------------------------------------------------------------
funcs=($(declare -F -p | cut -d " " -f 3))
declare -F -p : 列出所有自定义函数的名字 输出为: declare -f 函数名
cut -d " " -f 3 : 以 " " 为分隔符切割,选取第三个
($()) 变成数组
${funcs[@]} 数组所有值
--------------------------------------------------------------------------------------------------------
until语句 :提供循环执行,它与while循环相反, until循环将反复执行直到条件为真就结束循环,而while循环条件为假就结束循环。
使用格式:
until [ 测试条件 ]
do
语句 #可以是多条语句
done
------------------------------------------------------------------------------------------------------------