views:

1424

answers:

3

Redirecting command output:

eg:

echo "Foo `./print_5_As.rb`"

would echo "Foo AAAAA"

Thanks

+1  A: 

In CMD.EXE you could do something like the following:

FOR /F %x IN ('"./print_5_As.rb"') DO echo %x
matli
+2  A: 

In Powershell, you use $( ) to evaluate subexpressions...

For example:

PS C:\> "Foo $(./print_5_As.rb)"
Foo AAAAA
Pete Richardson
+15  A: 

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)" in both PowerShell and Bash.

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 seperator in Windows. So, PowerShell uses the (now unused) backtick for escaping.

Jörg W Mittag
It's great reading answers like this where you get to learn how and why things are. Thanks! (I'd do +10 if I could.)
PEZ