![]() |
|
|
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 |
| Noob, script formatting query | benjo | Shell Programming and Scripting | 2 | 03-03-2008 07:37 AM |
| noob. need help to create a script. | aron | Shell Programming and Scripting | 1 | 07-09-2007 09:13 PM |
| Using PHP script with crontab (NOOB) | Bobafart | UNIX for Dummies Questions & Answers | 5 | 04-26-2007 10:32 PM |
| Email alert script | moon | Shell Programming and Scripting | 1 | 04-26-2002 05:55 PM |
| ALERT!!! ALERT!!! I messed up the UNIX!!! | Fwurm | UNIX for Dummies Questions & Answers | 15 | 11-06-2001 05:53 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Why does my script not work? (Noob Alert)
I am a scripting noob and I have tried to search on google, but cannot find the answer as to why this script doesn't work properly.
The idea of this script is that it will list all files starting with f in a certain folder, and delete all but the three newest one. I am trying to achieve this by doing command "ls -t" so the newest come out on top. Then I simply skip the first 3 and start deleting what comes after (in the supplied script I am just renaming the files). For some reason when the counter hits 10, it seems to think that it a smaller value than 3. I think it only sees the 1st character of 10, leading it to think its value is 1? Yet when I echo $counter, it says 10? I am sure you are going to slap me around the ears with one-line scripts that do the job, but as I am trying to learn I would really like to see why mine does not work as well. I really do apreciate any kind of input. Thanks in advance. My script: #!/bin/bash declare -i counter=1 for file in $(ls -t f*); do if [[ $counter > 3 ]]; then mv $file $file.del fi let counter=$counter+1 done exit 0 |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|