setting an environment variable via the output of a command

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top