Re: Adding to the command line via variables
From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 07/31/05
- Next message: Greg Andrews: "Re: Adding to the command line via variables"
- Previous message: Bill Marcum: "Re: Adding to the command line via variables"
- In reply to: Jeff Kloek: "Adding to the command line via variables"
- Next in thread: Greg Andrews: "Re: Adding to the command line via variables"
- Reply: Greg Andrews: "Re: Adding to the command line via variables"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 30 Jul 2005 19:06:53 -0400
On 2005-07-30, Jeff Kloek wrote:
> Hello. I'm trying to figure out how I can build a command line using the
> output of the ls |grep command. The problem is the number of files returned
> will vary.
> As an example, one time might find output1, output2 and output3, and another
> time it might also include output4 and output5.
>
> How can I use the output of "ls |grep output" to build a command line that
> does the following:
> lp -d printername outputX outputX outputX ?
> I don't expect to ever exceed the allowable count of command line
> parameters.
> Any ideas would be greatly appreciated!!
Unless you need a regular expression to select the files, there is
no need for ls or grep. To print all the files beginning with
"output", just use:
lp -d printername output*
If you do need to use a regular expression, there's still no need
for ls:
lp -d $(printf "%s\n" * | grep REGEX)
Using anything other than wildcard expansion will present problems
if the filenames are badly formed (e.g., if they contain spaces).
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
==================================================================
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/cfaj/ssr.html>
- Next message: Greg Andrews: "Re: Adding to the command line via variables"
- Previous message: Bill Marcum: "Re: Adding to the command line via variables"
- In reply to: Jeff Kloek: "Adding to the command line via variables"
- Next in thread: Greg Andrews: "Re: Adding to the command line via variables"
- Reply: Greg Andrews: "Re: Adding to the command line via variables"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|