#!/bin/bash
:<<eof
命令替换,命令的执行结果为另一个命令的参数(获取命令执行结果)- `command`
- $(command)
``和$()两者是等价的,但推荐初学者使用S(),易于掌握;
缺点是极少数UNIX可能不
$(())主要用来进行整数运算,包括加减乘除,引用变量前面可以加$,也可以不加$
3
a=1
b=2
echo $((a+b))echo $(($a+$b))
eof
# 命令出错会停止执行set-e
# 打印每条执行的命令# set -x# 获取系统所有用户并输出
index=0
for user in `cat/etc/passwd | cut -d ":"-f 1`
doecho"This is $index user: $user"
index=$[$index+1]
done
# 根据系统时间计算去年时间echo"This is $(date +%Y) year,and last year is $[$(date +%Y) - 1]"echo"This is $(date +%Y) year,and last year is $(($(date +%Y)- 1))"# 根据系统时间计算今年还有多少个星期,已经过去了多少个星期echo"There are $[$[366-$(date +%j)]/7 ] weeks left in this year,and $[$(date +%j) / 7 ] weeks had gone"set+x