DO /P?

#1
1. There is no link from "DO /P" (at the top of DO's help) to the explanation at the bottom.

2. I figured the opening '(' of DO's command would signal the end of DO's control arguments. So I was surprised at:
Code:
c:\users\vefatica\desktop> do l in /P grep aablock inbound.txt | cut -f1 ( echo %@word["/",1,%l] )
cut: fatal error: Can not open file '('
Usage : DO [n | FOREVER]
Double-quoting "grep ... | cut -f1" doesn't work. Back-quoting it works, as well as escaping the '|'. Is there a correct way?
 

rconn

Administrator
Staff member
May 14, 2008
10,567
97
#2
1. There is no link from "DO /P" (at the top of DO's help) to the explanation at the bottom.
There is a link, and it works fine here.

2. I figured the opening '(' of DO's command would signal the end of DO's control arguments. So I was surprised at:
Code:
c:\users\vefatica\desktop> do l in /P grep aablock inbound.txt | cut -f1 ( echo %@word["/",1,%l] )
cut: fatal error: Can not open file '('
Usage : DO [n | FOREVER]
Double-quoting "grep ... | cut -f1" doesn't work. Back-quoting it works, as well as escaping the '|'. Is there a correct way?
The opening '(' isn't in DO, nor is it even in the same session as DO. "Cut" has been started in a child pipe session, and it has been passed the remainder of the command line ("-f1 ( echo %@word["/",1,%l] )") -- and I think it's unlikely that CUT is going to be able to understand any of that. It certainly isn't going to be able to process the DO argument or the variable function.

You should either group the grep / cut block:

do l in /P (grep aablock inbound.txt | cut -f1) ( echo %@word["/",1,%l] )

or use back quoting. Either will work. (As will escaping the pipe, though that's a little less clear to someone reading the line.)