I had a great trick in the Windows cmd.exe(at least up to XP), to emulate the UNIX echo behavior without the new line echo -n. For example, the command:
<nul: set /p junk= xyzzy
exactly six characters will be output, the leading space and the string "xyzzy", and nothing more.
If you're wondering why this works, this is actually an input command that outputs " xyzzy", since the prompt is waiting for user input before assigning this input to a variable junk. In this particular case, it does not wait for user input, since it captures the input from the device nul.
This was quite useful in scenarios cmdwhen (for example) it processes files in a loop (one iteration per file), where you want to list more than one per line. Using this trick, you can simply print each file name followed by a space, not a new line, after that, after the loop ends, print a new line:
Processing files:
file1.txt file42.txt p0rn.zip
Now I find that on Windows 7, spaces are no longer output, so I get:
Processing files:
file1.txtfile42.txtp0rn.zip
Is there a way to get set /pto start honoring my spaces again, or is there another way in Win7 to achieve the same effect?
I tried quotes using .(which works in echo) and even avoids the c line ^, but none of them work:
C:\Pax> <nul: set /p junk= xyzzy
xyzzy
C:\Pax> <nul: set /p junk=" xyzzy"
xyzzy
C:\Pax> <nul: set /p junk=' xyzzy'
' xyzzy'
C:\Pax> <nul: set /p junk=. xyzzy
. xyzzy
C:\Pax> <nul: set /p junk=^ xyzzy
xyzzy
What I need:
C:\Pax> some_magical_command_with_an_argument xyzzy
xyzzy
which will give me a space at the beginning and without a new line at the end.