#!/bin/bash
#!/bin/bash
var1=1
var2=2
var3=$[var1+var2]
echo "$var3"
sh test.sh 我是参数1 我是参数2 我是参数3
#!/bin/bash
# 文件名称 value:test.sh
var0=$0
var1=$1
var2=$2
var3=$3
echo "param1: $1"
echo "param2: $2"
echo "param3: $4"
echo "全部参数合成一个str:$*"
echo "全部参数数组:$@"
#!/bin/bash
array=(A B "C" D)
echo "第一个元素:${array[0]}"
echo "第二个元素:${array[1]}"
echo "第三个元素:${array[2]}"
echo "第四个元素:${array[3]}"
echo "数组元素为: ${array[*]}"
echo "数组元素为: ${array[@]}"
echo "数组元素个数为: ${#array[*]}"
echo "数组元素个数为: ${#array[@]}"
var=(1 2 3 4 5 6)
for item in ${var[@]}
do
echo "$item"
done
#!/bin/bash
var1=1
var2=2
var3=3
file="/usr/local/sh/1.txt"
if [[ $var1 -eq 2 || $var2 -eq 3 ]]
then
echo "等于!"
else
echo "不等于!"
fi
if [ ! -e $file ]
then
touch $file
echo "文件不存在,创建文件:$file"
else
echo "文件存在!"
fi
#!/bin/bash
param1=$1
param2=$2
function fun1(){
return $[param1+param2]
}
fun1
echo "结果为:$?"
原文:https://www.cnblogs.com/GoslingWu/p/14469620.html