Shell脚本练习

#!/bin/bash

echo "hello world!"
exit 0
#!/bin/bash

read -p "Please input your first name:" firstname
read -p "Please input your last name:" lastname

echo "Your full name is:$firstname $lastname"
#!/bin/bash

echo "I will use touch command to create 3 files."
read -p "Please input your filename:" fileuser

filename=${fileuser:-"filename"}

date1=$(date --date='2 days ago' +%Y%m%d)
date2=$(date --date='1 days ago' +%Y%m%d)
date3=$(date +%Y%m%d)

file1=${filename}${date1}
file2=${filename}${date2}
file3=${filename}${date3}

touch "$file1"
touch "$file2"
touch "$file3"
#!/bin/bash

echo "You should input 2 numbers,, I will cross them!"

read -p "first number:" firstnu
read -p "second number:" secondnu

total=$(($firstnu * $secondnu))

echo "The result of $firstnu * $secondnu is ==> $total"
#!/bin/bash

echo "Please input a filename, I will check the filename's type and permission."

read -p "Input a filename:" filename

test -z $filename && echo "You must input a filename." && exit 0

test ! -e $filename && echo "The filename '$filename' do not exist" && exit 0

test -f $filename && filetype="regulare file"
test -d $filename && filetype="directory"
test -r $filename && perm="readable"
test -w $filename && perm="$perm writable"
test -x $filename && perm="$perm executable"

echo "The filename:$filename is a $filetype"
echo "And the permissions are:$perm"
#!/bin/bash

read -p "Please input(Y/N):" yn

[ "$yn" == "Y" -o "$yn" == "y" ] && echo "OK, continue" && exit 0
[ "$yn" == "N" -o "$yn" == "n" ] && echo "Oh, interrupt!" && exit 0

echo "I don't know what your choice is" && exit 0
#!/bin/bash

read -p "Please input(Y/N):" yn

if [ "$yn" == "Y" ] || [ "$yn" == "y" ]; then
	echo "OK, continue"
	exit 0
fi

if [ "$yn" == "N" ] || [ "$yn" == "n" ]; then
	echo "Oh, interrupt!"
	exit 0
fi

echo "I don't know what your choice is" && exit 0
#!/bin/bash

read -p "Please input(Y/N):" yn

if [ "$yn" == "Y" ] || [ "$yn" == "y" ]; then
	echo "OK, continue"
elif [ "$yn" == "N" ] || [ "$yn" == "n" ]; then
	echo "Oh, interrupt!"
else
	echo "I don't know what your choice is"
fi
#!/bin/bash

echo "The script name is ==> $0"
echo "Total parameter number is ==> $#"

[ "$#" -lt 2 ] && echo "The number of parameter is less than 2. Stop here." && exit 0

echo "Your whole parameter is ==> '$@'"
echo "The 1st parameter ==> $1"
echo "The 2nd parameter ==> $2"
#!/bin/bash

echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '$@'"
shift # 迚行第一次『一个发量的 shift 』
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '$@'"
shift 3 # 迚行第二次『三个发量的 shift 』
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '$@'"
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值