脚本打印变量扩展

时间:2016-06-23 21:46:32

标签: bash scripting crontab

我的脚本产生了一些非常奇怪的输出,我不知道为什么。

这是脚本: (userslist.temp是一个用户名列表,每个文件行一个)

printf 'Output Starting:\n\n'
while read line; do
    cronresult=$(sudo crontab -u $line -l)
    printf "$line : $cronresult"
done < userslist.temp

它产生的输出:

Output Starting:

no crontab for thornegarvin
thornegarvin : 
no crontab for testuserone
testuserone : 
no crontab for testusertwo
testusertwo : 
no crontab for testuserthree
testuserthree : 

我的用户没有配置crontabs,但我不知道脚本为什么不在单独的行上打印变量。

1 个答案:

答案 0 :(得分:0)

所以评论足以解决我的问题: 我捕获的输出是标准错误输出,而不是我想象的标准输出。我将stderr重定向到/ dev / null并设置if来处理空白stdoutput。谢谢!

相关问题