假设我有这个脚本:
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需要在写入文件时调用它?",您可能会问.
好吧,因为我只想对某些输出消息执行"可选重定向"操作.在上面的示例中,只应影响第二条消息.