在 Bash 上,cmd/PowerShell 相当于什么? [英] What's the cmd/PowerShell equivalent of back tick on Bash?

查看:19
本文介绍了在 Bash 上,cmd/PowerShell 相当于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重定向命令输出:

例如:

echo "Foo `./print_5_As.rb`"

会回声Foo AAAAA"

would echo "Foo AAAAA"

推荐答案

PowerShell 语法基于 POSIX ksh 语法(有趣的是不是在任何微软的语言上像 CMD.EXE、VBScript 或 Visual Basic for Applications),很多东西的工作方式与 Bash 中的几乎相同.在你的情况,命令替换是用

The PowerShell syntax is based on the POSIX ksh syntax (and interestingly not on any of Microsoft's languages like CMD.EXE, VBScript or Visual Basic for Applications), so many things work pretty much the same as in Bash. In your case, command substitution is done with

echo "Foo $(./print_5_As.rb)"

在 PowerShell 和 Bash 中.

in both PowerShell and Bash.

Bash 仍然支持古老的方式(反引号),但是PowerShell 清理了语法并删除了冗余诸如两种不同的命令替换之类的构造语法.这释放了不同的反引号在 PowerShell 中使用:在 POSIX ksh 中,反斜杠用作转义字符,但这会非常痛苦PowerShell 因为反斜杠是传统路径Windows 中的组件分隔符.因此,PowerShell 使用(现在未使用)用于转义的反引号.

Bash still supports the ancient way (backticks), but PowerShell cleaned up the syntax and removed redundant constructs such as the two different command substitution syntaxes. This frees up the backtick for a different use in PowerShell: in POSIX ksh, the backslash is used as escape character, but that would be very painful in PowerShell because the backslash is the traditional path component separator in Windows. So, PowerShell uses the (now unused) backtick for escaping.

这篇关于在 Bash 上,cmd/PowerShell 相当于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆