shell脚本,获取执行结果

Shell获取上一个命令执行结果,传递到下个命令执行,手写shell脚本

示例:

#!/bin/bash
echo "list gps image..."
docker images|grep gps
if [ $? -eq 0 ]; then 
	echo "success..."
	ret1=`docker images|grep gps`
	num=0
	for i in $ret1; do
		num=`expr $num + 1`
		if [ $num == 3 ];then
			echo "找到容器ID= $i "
			ret2=`docker rmi -f $i`
			if [ $? -eq 0 ];then
				echo "删除容器 ${i} 成功"
			else
				echo "删除容器 ${i} 失败"
				exit 1
			fi
			exit 1
		fi
	done
	echo $num
else
	echo "failed..."
	exit 1
fi
unset num
exit 1
posted @ 2022-05-19 16:57  melody#787  阅读(1968)  评论(0)    收藏  举报