written a srcipt with 2 arguments


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting written a srcipt with 2 arguments
# 1  
Old 04-29-2008
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  
Old 04-29-2008
Hi.
There are probably other (better) ways, but:
Code:
#!/bin/ksh

set -A ARGS $@

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

echo $FILE

Regards.
# 3  
Old 04-29-2008
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  
Old 04-29-2008
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  
Old 04-29-2008
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  
Old 04-29-2008
And pls the the remaining arguments goes into the middle of the file and not the begining or end of it.

Thank u.
# 7  
Old 04-29-2008
Quote:
Originally Posted by sam4now
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:
https://www.unix.com/unix-dummies-que...om-forums.html


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 06:17 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Debugging a program written in two languages

Subject: Debugging a program written in two languages Platform: Linux (Kubuntu) I am trying to debug a C application with bindings to some simple functions written in Ada using the GNAT Programming Studio IDE (GPS). The main entry point is in C. The debugger is gdb. I managed to compile... (0 Replies)
Discussion started by: NiGHTS
0 Replies

2. Solaris

syslog is not getting written

hi all syslog is not getting written. i am getting following two logs snmpd.log & authlog logs. please tell what are two logs snmpd.log & authlog logs. why syslog is not written. (16 Replies)
Discussion started by: nikhil kasar
16 Replies

3. Programming

book on linux application written with c

Just learned c language ,but I don't know where to start to write some applications under Linux ,I really appreciate it if anybody can help me find some books or sites on it. (2 Replies)
Discussion started by: hgdcjq
2 Replies

4. Shell Programming and Scripting

grep with two arguments to arguments to surch for

Hello, is it possible to give grep two documents to surche for? like grep "test" /home/one.txt AND /home/two.txt ? thanks (1 Reply)
Discussion started by: Cybertron
1 Replies

5. Programming

How is a new Web Development language written ?

I'm wondering how programmers develop new Web Development languages because I want to learn how everything begins from the start. Let's say I'm planning to write a new language for the Web. How do I do this? Is there anyone who knows about the way Web Development languages first appear ? I'm asking... (1 Reply)
Discussion started by: Anna Hussie
1 Replies

6. Shell Programming and Scripting

two question about expect srcipt

Hi experts, I have two question about expect script questions 1 send "tar -xjvf a.tar\r" send "ifconfig\r" I want to know if it just run "ifconfig after "tar -xjvf a.tar complete. or the two cmd run at the same time question 2 after I use the expect to ssh to the... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

7. Linux

check written data

I'm using growisofs to write DVD, e.g. $ growisofs -Z /dev/dvd -V "Personal Data, `date +"%b, %d %Y"`" -R -J /mnt/d/* How can I test whether data was written correctly? md5sum or so? (0 Replies)
Discussion started by: Hitori
0 Replies

8. Shell Programming and Scripting

Checking a file is not being written to

Hello All I am attempting to write a shell script (bourne shell script) which will copy a tar'd and compressed file from a directory to a staging area but will not know whether the file is still open for write since files are being ftp's to my site at random times during the day. Once I am... (14 Replies)
Discussion started by: kanejm
14 Replies

9. UNIX for Dummies Questions & Answers

Operating on a file being written by another application

Hi, I have a directory that is used to store files generated by another application. Each file is huge and can take some time to produce. I am writing a shell script to check the names and dates of the files and do some functions on the ones that are not being written out. My question is, if I... (3 Replies)
Discussion started by: GMMike
3 Replies

10. UNIX for Dummies Questions & Answers

File being used/written

Hello, Which command in unix can tell whether a file is being used/written by another process. e.g. If one process is copying a very big file in some directory and there is another cronjob process which checks for a new file and in this directory and process the file. I want to check, if the... (4 Replies)
Discussion started by: sanjay92
4 Replies
Login or Register to Ask a Question