编写一个简单的hello.sh脚本程序,目的是打印出hello world
https://blog.csdn.net/weixin_42107954/article/details/127094543
在Linux下通过vim创建一个hello.sh脚本
进vim编写脚本程序
#!/bin/bash
echo "hello world \a \n"
echo "you are the best"
第一行#!/bin/bash表明这个脚本使用的shell名称,因为使用的是bash,所以使用如上语句,表明运行时系统加载bash相关环境配置文件,保证下面语句得以运行;
运行脚本
第一种运行方式
sh hello.sh
第二种运行方式
./hello.sh
但可能会有权限问题,需要chmod。
编写一个批量上传指定镜像的脚本
上面这一段是用来指定到屏幕上字符的颜色的
$#
表示参数的个数
ne
=not equal
echo -e
表示将转码后的结果输出到屏幕
\033[xxm$1\033[0m
是ANSI控制码,根据xx的值不一样表示输出不同的颜色
https://blog.csdn.net/wuyvle/article/details/112386841
#!/bin/sh
# This script will upload the given local images to a registry server ($registry is the default value).
# See: https://github.com/yeasy/docker_practice/blob/master/_local/push_images.sh
# Usage: push_images image1 [image2...]
# Author: yeasy@github
# Create: 2014-09-23
#批量上传指定的镜像到注册服务器,默认是本地的注册服务器127.0.0.1:5000,可以通过修改registry的值上传到指定目标注册服务器
#The registry server address where you want push the images into
registry=127.0.0.1:5000
### DO NOT MODIFY THE FOLLOWING PART, UNLESS YOU KNOW WHAT IT MEANS ###
echo_r () {
[ $# -ne 1 ] && return 0
echo -e "\033[31m$1\033[0m"
}
echo_g () {
[ $# -ne 1 ] && return 0
echo -e "\033[32m$1\033[0m"
}
echo_y () {
[ $# -ne 1 ] && return 0
echo -e "\033[33m$1\033[0m"
}
echo_b () {
[ $# -ne 1 ] && return 0
echo -e "\033[34m$1\033[0m"
}
-----------------------------------------------------------------------------------
usage() {
sudo docker images
echo "Usage: $0 registry1:tag1 [registry2:tag2...]"
}
[ $# -lt 1 ] && usage && exit
echo_b "The registry server is $registry"
for image in "$@"
do
echo_b "Uploading $image..."
sudo docker tag $image $registry/$image
sudo docker push $registry/$image
sudo docker rmi $registry/$image
echo_g "Done"
done
$@
表示所有的参数