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
help needed nnayagam Shell Programming and Scripting 2 03-07-2008 06:34 AM
Little help needed. Netghost AIX 5 08-10-2006 03:29 PM
Help needed dsravan Shell Programming and Scripting 2 07-20-2006 10:37 AM
awk help needed. cskumar Shell Programming and Scripting 0 07-20-2006 08:24 AM
Sed help needed stevefox Shell Programming and Scripting 5 12-05-2005 01:44 AM

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 03-17-2006
Toxic Toxic is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 8
Help needed

The following program works fine; however, I don't understand the following line of it.
cp $1 $1.BAK-$i

You can make backup copies of a file using the following program.
What is '' -$i '' ?

If you have a file named 'text' , this will create '' text1.BAk , text.BAK2, text.BAK3, etc.
What is '' $1.BAK -$I '' ?

Your help is appreciated.
------------------------------------------------
#!/bin/sh
for i in 0 1 2 3 4 5 6 7 8 9 ; do
cp $1 $1.BAK-$i
done
  #2 (permalink)  
Old 03-17-2006
buffoonix buffoonix is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 145
Is this an excercise from a shell scripting course?
Otherwise the loop doesn't look very useful to me.
It only creates ten copies of a file whose name has been passed
as 1st argument to the script and gives each copy the extension .BAK-[0-9]
  #3 (permalink)  
Old 03-17-2006
Toxic Toxic is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 8
buffonix

I am not studying nowadays. I studied those things nearly 1 year ago.

Now I am trying to brush up my knowledge using online resources.

I have forgotten a lot of basics.

What is this '' -$i '' is doing is not clear to me?

The '' - '' (minus) sign is a puzzle for me.
  #4 (permalink)  
Old 03-17-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
That's a dash and not a minus sign in your example "BAK-" is BAK with a dash.

This script:
Code:
#!/bin/sh
for i in 0 1 2 3 4 5 6 7 8 9 ; do
    cp $1 $1.BAK-$i
done
is taking an argument, which is expected to be a file and creating 10 copies of it.

Example:
yourscript.sh MyFile.txt
results in 10 copies named MyFile.txt.BAK-0, MyFile.txt.BAK-1, MyFile.txt.BAK-2, MyFile.txt.BAK-3, etc.
  #5 (permalink)  
Old 03-18-2006
Toxic Toxic is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 8
Thanks tmarkile

Now things are clear to me. I will be posting more and more in the coming few days. I am trying to study or rather brush up my knowledge using some online resources.

I really appreciate your assistance.
  #6 (permalink)  
Old 03-18-2006
Toxic Toxic is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 8
Tmarikle


Why do you want to name the script as '' yourscript.sh '' ?

You could just name 'yourscript' . I don't know the necessity of the '' .sh ''

Please tell me.

My default shell is the 'bash' .
[nissanka@c83-250-111-20 ~]$ echo $SHELL
/bin/bash
[nissanka@c83-250-111-20 ~]$
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 03:09 PM.


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