此命令单独运行时,将产生预期的结果(crontab的最后一行):
tail -n 1 /etc/crontab
但是,当我将其作为echo命令的一部分运行以将结果发送到文件时,它会添加工作目录中所有文件的摘要以及预期结果:
sudo bash -c 'echo $(tail -n 1 /etc/crontab) > /path/to/file'
为什么此命令产生额外的数据?
2
请参阅为什么我的shell脚本在空白或其他特殊字符上会阻塞?和为什么的printf比回声?
—
斯特凡Chazelas
echo
在这里为您做什么?还考虑tail -n 1 /etc/crontab | sudo tee /path/to/file >/dev/null