shell 脚本基础

#!/bin/bash
:<<!   
echo "shell 传参测试";
echo "第一个参数是 $0";
echo "第二个参数是 $1";
echo "第三个参数是 $2";

s1=${1:-mmiao}
echo "第三个参数是 $s1";
!
#echo "miaoman"

echo "---0---test for loop  array"
a2=(1 5 8 9 10)
length=${#a2[@]}
echo "array len is $length"

echo "array : ${a2[0]} ${a2[1]} ${a2[2]} ${a2[3]} ${a2[4]}"
for var in 0 1 2 3 4
do
	echo " var=${a2[var]} "
done

echo "---1---test case "
case $1 in
	1)
		echo "1---"
		;;
	2)
		echo "2---"
		;;
	*)
		echo "unknown -----"
		;;
esac

echo "---2---test local var func return value"
temp=2
echo "temp = $temp"
function return_test()
{
	local temp=3
	echo "local temp = $temp"

	local temp1=4
	echo "local temp1 = $temp1"	
	
	return $1
}

return_test 0
echo $?

return_test 1
echo $?

echo "temp = $temp"
echo "local temp1 = $temp1"	

echo "---3---test file found "	
a=mmiao
if [ ! -f ${a} ]
then
	echo "not found"
else
	echo "found"
fi

echo "---4---test dirname word bit "	
echo "$(dirname "$0")"
echo "$(getconf WORD_BIT)"
echo "$(getconf LONG_BIT)"

echo "---5---test -a"

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值