来源:https://coding.m.imooc.com/classindex.html?cid=314
语法:
语法格式 | |
方法一 | ·command· |
方法二 | $(conmand) |
作用:
将一个命令的结果作为另一个变量的参数
例子:
输出当前系统时间是当年的第几天、第几个星期、还有多少天,还有多少个星期
#!/bin/bash
#
echo -e "This year have passed $(date +%j) days"
echo -e "This year have passed $(($(date +%j)/7)) weeks"
echo -e "There is $((365 - `date +%j`)) days befor new year"
echo -e "There is $(((365 - `date +%j`)/7)) weeks befor new year"
输出linux系统的所有用户
index=1
for user in `cat /etc/passwd | cut -d ':' -f 1`
do
echo "This is $index user $user"
index=$((index+1 ))
done