I would like to convert this /bin/sh syntax into a widely compatible Windows batch script:
host=`hostname`
echo ${host}
How to do this so that it’ll work on any Windows Vista, Windows XP, and Windows 2000 machine?
To clarify: I would then like to go on in the program and use the hostname as stored in the variable host. In other words, the larger goal of the program is not to simply echo the hostname.
I usually read command output in to variables using the
FORcommand as it saves having to create temporary files. For example:Note, the above statement will work on the command line but not in a batch file. To use it in batch file escape the
%in theFORstatement by putting them twice:There’s a lot more you can do with
FOR. For more details just typeHELP FORat command prompt.