In Unix, we can put multiple commands in a single line like this:
$ date ; ls -l ; date
I tried a similar thing in Windows:
> echo %TIME% ; dir ; echo %TIME
But it printed the time and doesn’t execute the command dir.
How can I achieve this?
Use:
This is, from memory, equivalent to the semi-colon separator in
bashand other UNIXy shells.There’s also
&&(or||) which only executes the second command if the first succeeded (or failed), but the single ampersand&is what you’re looking for here.That’s likely to give you the same time however since environment variables tend to be evaluated on read rather than execute.
You can get round this by turning on delayed expansion:
That’s needed from the command line. If you’re doing this inside a script, you can just use
setlocal: