[bash]调用linux命令获得结果存入变量的两种方式

代码:

#!/bin/bash

ls=$(ls)
echo $ls

whoami=`whoami`
echo $whoami

执行结果:

[os-××××××××101z ~]$ sh cmd2.sh
1.py 2020-03-16-b020 AllocationReq_0030_20200306142925.csv AllocationReq_0104_20200310145723.csv AllocationReq_0104_20200310145723.end clean.py cmd2.sh hname.sh mkdirs.py test.txt webclean.sh work.nfs
os-hy01

--2020-03-18--

posted @ 2020-03-18 17:20  逆火狂飙  阅读(1183)  评论(0)    收藏  举报
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东