Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Linux (Bash), there's a way to use a command as a parameter for another command, using back-ticks:

> echo ===== `time` =====

This would print:

===== The current time is: 12:22:34.68 =====

Is there a way to do this in cmd.exe on WIndows ?

share|improve this question
see this post – Prince John Wesley May 27 '11 at 9:38
Also see this this post (use of doskey command from cmd) – misterjaytee May 27 '11 at 11:00
@misterjaytee: Command substitution and aliases are different things. – grawity May 27 '11 at 13:59
@grawity - Thanks for pointing that out - Note to self: must read the question properly before responding... – misterjaytee May 30 '11 at 13:26
up vote 6 down vote accepted

Try this:

echo. ===== %time% =====

I know this may not be what you want, because you mentioned command substitution... So this may be it:

for /f "usebackq tokens=*" %i in (`date/t&time/t`) do echo.  ===== %i =====

For more hints about the usage of usebackq try this command:

for /?
share|improve this answer
Yep, for /f is what I was looking for. Thanks! On a side note: It's so kludgy and hard to remember (compared to the bash way). I should give up "bat programming" and learn something more productive - PowerShell maybe? – Cristi Diaconescu Jul 7 '11 at 20:10

In Windows the '( )' operator has a similar behavior as the Bash command substitution.

This Linux script:


echo $my_linux_command=$(ls)
echo $my_alternate_linux_command=`ls`

gives a similar result as Windows PowerShell:

$my_windowsPS_variable = (dir)


and as Windows CMD:

set my_windowsCMD_variable=(dir)
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .