Friday, June 26, 2009

To Be Continued

I hate backslashes. They make code harder to read.

In these four code snippets, I like the first two, but not the last two:
sleep 10 & date

sleep 10 &
date

sleep 10 & \
date

sleep 10 \
& date
So? So, for the same reason, I would re-write:
grep :0: /etc/passwd | \
wc -l

as
grep :0: /etc/passwd |
wc -l

and
grep -c jsh /etc/passwd \
|| echo jsh not found

as
grep jsh /etc/passwd ||
echo jsh not found
The symbols ', ", `, &, |, &&, and ||, at the ends of lines, say "I'm not done," and automatically continue to the next line (or, in the case of the quote, until the closing quote).

For shell symbols with parens, like $( and <(, the continuation is until the matching, closing paren.

No comments: