![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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] |
|
||||
|
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. |
|
||||
|
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
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. |
|
||||
|
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 ~]$ |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|