The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
alias two words command line harlock59 Shell Programming and Scripting 3 07-14-2009 08:32 AM
how to extend words on a command line ? venhart UNIX for Dummies Questions & Answers 6 07-16-2008 11:22 AM
overlapping words on command line gaurav123 UNIX for Dummies Questions & Answers 4 07-01-2008 12:21 PM
displaying mutliple fields on command line Trellot UNIX for Dummies Questions & Answers 3 11-02-2007 07:37 AM
Identify duplicate words in a line using command srinivasan_85 UNIX for Dummies Questions & Answers 8 05-01-2007 02:29 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 4 Weeks Ago
patryk44 patryk44 is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 2
How to set mutliple words variable from command line

I'm writing a script (C shell) to search for a pattern in file. For example
scriptname pattern file1 file2 filenN
I use for loop to loop through arguments argv, and it does the job if all arguments are supplied. However if only one argument is supplied (in that case pattern ) it should ask to input file name or names, and then check for pattern. How I can set variable to include multiple words input from command line so I can use it in loop. Or even better is it possible to assign command line input to argv, so I don’t have to use the same loop twice only because it is different variable name (one to loop through argv if more than on argument, and second to loop through filenames variable if only one argument supplied). Below is the part of my script which is causing problem:

Code:
set pattern = $1 
if ($#argv == 1) then
    echo "Enter name of files"
    set filenames = $< #how I can set it to accept more than word?
endif

Any help will much appreciated.

Last edited by Neo; 4 Weeks Ago at 12:59 PM.. Reason: Added code tags.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0