bash - Difference between ">& log" and ">& log&"
问题描述
I don't get what is the difference between all these commands in bash,
echo "Hello world" > log&
echo "Hello world" >& log
echo "Hello world" >& log&
What does each & do?
As far as I understand putting & at the end send the whole thing to the background. But what about the & after the > ?
Is there any advantage of writing
echo "Hello world" >& log&
instead of
echo "Hello world" > log&
解决方案
根据The Bash Reference Manual , §3.6.4 "Redirecting Standard Output and Standard Error",该>&
符号将标准输出和标准错误一起重定向。
在您的具体示例中,我不希望echo "Hello world"
向标准错误写入任何内容,因此&
不会真正改变任何内容;但如果它确实将东西写入标准输出和标准错误,那么log
最终会同时出现。
顺便说一句,在同一节中,等价的符号&>
优于>&
(大概是因为>&
容易与类似的符号混淆>&1
,后者的作用完全不同)。
推荐阅读
- java - Jetty 使用 AbstractHandler 进行异步处理
- docker - docker中的控制台应用程序不起作用
- flutter - 如何删除或更改flutter_bootstrap列之间的空间
- amazon-web-services - 用户注册后请求的页面遇到错误
- azure-maps - 如何在天蓝色地图中更改不同国家的背景颜色
- mysql - 我的 nodeJS express 后端工作,然后突然崩溃
- c# - 如何在 C# 中深度克隆包含 DynamicObject 的类?
- azure - 为什么直到循环提前结束?
- c# - 如何使用 .NET 对构建进行签名?
- google-play-console - APK 需要有效的隐私政策您的应用正在上传用户的主要帐户信息