Jua*_* C. 5 bash powershell pipeline
在 powershell 中$_是通过管道传递的当前变量的名称。Bash 中与此等效的是什么?
假设我想这样做
echo "Hi" | echo "$_"
prints Hi
Run Code Online (Sandbox Code Playgroud)
谢谢
Bash(或任何其他 Unix shell)没有这样的东西。
在PowerShell中,通过管道传递的是一个对象。在 bash 中,这是命令的输出(到标准输出)。
您可以做的关闭事情是使用while:
thecmd | while read theline; do something_with "$theline"; done
Run Code Online (Sandbox Code Playgroud)
请注意,IFS使用了(输入字段分隔符),因此您还可以执行以下操作:
thecmd | while read first therest; do ...; done
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3451 次 |
| 最近记录: |