linux sh脚本语法教程

  1. 文件格式
#!/bin/bash

# 具体指令、逻辑...
  1. 系统变量、定义变量、使用变量
  2. 遍历数组,for循环
#!/bin/bash
arr=("0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "e" "e" "f")
for value in ${arr[@]}
do
  echo $value
done


# 或者采取如下方式
echo "----------------------another way----------------------"

for (( i = 0 ; i < ${#arr[@]} ; i++ ))
do
  echo ${arr[$i]}
done
  1. if条件

if [ -z "$1" ];then   
   echo "xxx!"
fi


if [ -z "${DB_tmp}" ]; then
    continue # break;
else
   
fi

  1. 计算耗时
    https://cloud.tencent.com/developer/article/1441802
#!/bin/bash

start=$(date +%s)

sleep 5;

end=$(date +%s)
take=$(( end - start ))
echo Time taken to execute commands is ${take} seconds.

你可能感兴趣的:(linux,服务器,java)