且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Bash 上,cmd/PowerShell 相当于什么?

更新时间:2022-03-27 05:29:48

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.