The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
check written data Hitori Linux 0 07-22-2006 08:46 AM
Simple shell script to be written shsandeep Shell Programming and Scripting 6 07-17-2006 02:46 AM
Checking a file is not being written to kanejm Shell Programming and Scripting 14 01-20-2006 08:29 AM
Operating on a file being written by another application GMMike UNIX for Dummies Questions & Answers 3 02-01-2005 04:06 PM
File being used/written sanjay92 UNIX for Dummies Questions & Answers 4 10-13-2001 01:31 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-29-2008
sam4now sam4now is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 23
written a srcipt with 2 arguments

hello all
pls can anybody point me a direction of capturing 2 arguments: one a line of text the other is a file.

In paticular how can i get the file

so for exampls, i create a script called monalisa

monalisa this is an angel from the 7th heaven booboo

where monalisa is the script name, booboo is the name of the file and the rest are the line of text.]

can any body help.
  #2 (permalink)  
Old 04-29-2008
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
  
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
Hi.
There are probably other (better) ways, but:
Code:
#!/bin/ksh

set -A ARGS $@

FILE=${ARGS[$(expr $# - 1)]}

echo $FILE
Regards.
  #3 (permalink)  
Old 04-29-2008
sam4now sam4now is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 23
hello
have u tried d code, its not working. i just want to get the file and rest of the argument, so that the rest of the arguments can be placed in the file

thank u
  #4 (permalink)  
Old 04-29-2008
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
  
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
Yes, I've tryed it and works. Tough, in the example, the script only takes the file name and echoes it. From that, doing the rest is easy.... For instance:
Code:
#!/bin/ksh

set -A ARGS $@

FILE=${ARGS[$(expr $# - 1)]}

echo $@ | sed s/$FILE// >> $FILE
  #5 (permalink)  
Old 04-29-2008
sam4now sam4now is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 23
well i cant use sed at the moment am not on that chapter yet.

any other way would be nice. And pls can give an explanation of the code in details

Thanks
  #6 (permalink)  
Old 04-29-2008
sam4now sam4now is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 23
And pls the the remaining arguments goes into the middle of the file and not the begining or end of it.

Thank u.
  #7 (permalink)  
Old 04-29-2008
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
  
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
Quote:
Originally Posted by sam4now View Post
And pls can give an explanation of the code in details

Thanks
set -A ARGS $@ defines ARGS as an array and initializes it with the script arguments.

$@ is the list of arguments itself.

FILE=${ARGS[$(expr $# - 1)]} assigns the last argument to the FILE variable. This is the way arrays are managed on ksh

$# is the number of arguments, so

expr $# -1 is the position of the last one within the array

Is this homework or something? Have a look to rule #6 on:
Simple rules of the UNIX.COM forums:


My intention was to give you some hints so try first to do it for yourself, then ask the forum.

Regards.

Last edited by grial; 04-29-2008 at 05:17 AM..
Sponsored Links
Closed Thread

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 05:23 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