09/02/2010

Dos tricks that make me sick

It's been a while since I have had to use the dos shell for anything more than trivial scripting.

The DOS shell is Evil it was _designed_ to make people crazy, I can't think of any other explanation.

Here, have a quick look at some of the tricks you will have to come up with if you want some basic shell scripting features.

Set a variable with a command's result:

for /F %%x in (`echo value`) do set var=%%x

Then var is equal to "value".That's because having

set var=`echo value`
would have been to easy....

Did I mention you can only have one command in a for loop, unless you use labels and gotos ? that's just plain sick.

While I am at it, assume you have a variable, let's call it %var%, imagine its value is 1 like so :

set var=1
Now try and append that to a file with an echo, like so:
echo foo=%var%>>test.txt
what do you expect in test.txt ? why, but nothing more than
foo=
why in hell whould the 1 be present in the output? obviously you must use
echo foo=^%var%>>test.txt
to get
foo=1
Who could _not_ think of using ^ for such an obvious corner case as a NUMBER ?!! Seriously ?

I want my posix shell back !

Aucun commentaire: