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
sed very confused minifish Shell Programming and Scripting 14 04-14-2008 01:08 PM
confused sauravjung UNIX for Dummies Questions & Answers 1 04-07-2008 11:08 AM
confused about tar frustrated1 SUN Solaris 5 06-24-2004 11:50 AM
confused hapiworm UNIX for Dummies Questions & Answers 4 06-17-2002 03:30 PM

Closed Thread
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
  #1 (permalink)  
Old 05-23-2005
C|[anti-trust] C|[anti-trust] is offline
Registered User
  
 

Join Date: Apr 2005
Location: Australia
Posts: 30
Arrow confused with cp

may i know what

Code:
cp $1 $2
    $0 $2

does?
  #2 (permalink)  
Old 05-24-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Did you come up with this ?



Code:
cp $1 $2
    $0 $2

If you are trying to provide multiple arguments for cp, this is what man cp has to say..

Code:
DESCRIPTION
       Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

Keeping your command in tune with the man cp, we probably might have the following:


Code:
cp $1 $0 $2

which is self explanatory as per the man page.

Hopefully , this is what you were looking for.

Vino
  #3 (permalink)  
Old 05-24-2005
C|[anti-trust] C|[anti-trust] is offline
Registered User
  
 

Join Date: Apr 2005
Location: Australia
Posts: 30
well, i read in a book,


Code:
if [ $# -eq 2 ]; then
	cp $1 $2
	$0 $2
else
	tmp=`cat $1 | wc -l`
	echo $tmp
	while [ $tmp -ne 0 ] ; do
		echo `head -$tmp $1 | tail +$tmp` >> $1.tmp
		tmp=$(($tmp -1))
	done
	mv $1.tmp $1
fi

but i cant figure out how this


Code:
cp $1 $2
	$0 $2

could affect the script
  #4 (permalink)  
Old 05-24-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
That looks better.


Code:
if [ $# -eq 2 ]; then
	cp $1 $2
	$0 $2
else

Here's my analysis.

If you have 2 command line arguments provided by the user, then make argument 2 the same as argument 1.

And after you are done with that,

execute the script with $2 as an argument. In the shell scripting world, $0 holds the name of the script. So basically, you call the script with the value held in $2.

Let me know if you dont understand.

Vino

Last edited by vino; 05-24-2005 at 04:41 AM..
  #5 (permalink)  
Old 05-24-2005
C|[anti-trust] C|[anti-trust] is offline
Registered User
  
 

Join Date: Apr 2005
Location: Australia
Posts: 30
hmm so it is a recursivity script
thanks
  #6 (permalink)  
Old 05-24-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Not a recursive one. I made a mistake in my explanation.

The point is..

If you have two arguments, then make arg1 and arg2 the same.

Else, find the numbers of lines in $1 and carry on ..

Vino
  #7 (permalink)  
Old 05-25-2005
C|[anti-trust] C|[anti-trust] is offline
Registered User
  
 

Join Date: Apr 2005
Location: Australia
Posts: 30
Talking

Quote:
Originally Posted by C|[anti-trust]
may i know what

Code:
cp $1 $2
    $0 $2

does?
well im not talking about recursivity!
i wish to know how does this work?
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 09:01 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