小编dse*_*ton的帖子

将输出写入$ file(允许它为stdout)

假设我有这个脚本:

logfile=$1
echo "This is just a debug message indicating the script is starting to run..."

# Do some work...

echo "Results: x, y and z." >> $logfile
Run Code Online (Sandbox Code Playgroud)

是否可以从命令行调用脚本,这$logfile实际上是stdout?


为什么?我想有一个脚本将其部分输出打印到stdout或者可选地打印到文件.

"但是,为什么不删除>> $logfile部件,只./script >> filename需要在写入文件时调用它?",您可能会问.

好吧,因为我只想对某些输出消息执行"可选重定向"操作.在上面的示例中,只应影响第二条消息.

unix bash shell command-line sh

1
推荐指数
1
解决办法
76
查看次数

标签 统计

bash ×1

command-line ×1

sh ×1

shell ×1

unix ×1