setting an environment variable via the output of a command

  • Thread starter Thread starter Timothy Stone
  • Start date Start date
T

Timothy Stone

List,

So here's a cross over question... how can I set a batch
or shell/environment variable from the output of a
command. For instance, in Linux, I can:

### myscript.sh ###
#!/bin/sh

YEAR=`date +%Y`
MONTH=`date +%m`
DATE=${YEAR}${MONTH}
echo $DATE

###

$ ./myscript.sh
200401

Yet the similar execution does not work as expected:

### mybatch.bat ###
set DATE=`date`
echo %DATE%

###

C:\> echo %DATE%
`date`

What is the equivilent? Or is it not possible? I need a
specific formating of a temp filename based on date for
debugging. It is not a solution requiring WSH or
VBScript. I need a simple double clickable solution that
will be seldomly used.
 
Back
Top