How can you perform command substitutions at the Windows command-prompt?
Command substitution is a very powerful concept of the UNIX shell. It is used to insert the output of one command into a second command. E.g. with an assignment:
$ today=$(date) # starts the "date" command, captures its output
$ echo "$today"
Mon Jul 26 13:16:02 MEST 2004This can also be used with other commands besides assignments:
$ echo "Today is $(date +%A), it's $(date +%H:%M)"
Today is Monday, it's 13:21This calls the date command two times, the first time to print the week-day, the second time for the current time.
I need to know to do that in the command-prompt, (I already know that there is a way to perform something like that using as part of the for
command, but this way is much more obfuscated and convoluted.
Best Answer
You cannot do that in DOS.
If by DOS you mean the Windows Command Processor
cmd.exe
then you can get the output of a command withfor /f
:Depending on your requirements this can get a little more complex.