If you’ve been batch scripting on Windows for a while, you probably know the way to echo a blank line: a period with no space in front of it.
echo.
And the way to chain commands together:
- A || B runs B if A failed
- A && B runs B if A succeeded
- A & B runs B regardless
It may not be obvious, but you can echo multiple lines into a pipe without resorting to a temp file.
(echo def& echo abc) | sort
You will have to butt the ampersand against the end of each echo, or you’ll be sending spaces at the end of each line.
If you make a lot of lines, mashing them together gets hard to read. The solution to that obscure situation is below.
Edit (2010-04-25): Argh! Ampersand butting works for redirecting to a file, and FOR loops (as you’ll see in a later post), but plain ol’ pipes still get trailing spaces!
Example: Pipe into sort, get spaces. Dump to tmp.txt, no spaces.
My “Right Way”, below the fold, somehow only got a space on the final line.
(more…)