bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FWD: About Bash Script


From: Curtis
Subject: Re: FWD: About Bash Script
Date: Mon, 15 Feb 2010 13:45:06 -0800 (PST)
User-agent: G2/1.0

On Feb 15, 3:20 pm, Mart Frauenlob <mart.frauen...@chello.at> wrote:
> > -------- Original Message --------
> > Subject:   About Bash Script
> > Date:      Mon, 15 Feb 2010 10:39:25 -0600
> > From:      Curt <cain...@gmail.com>
> > To:        mart.frauen...@chello.at
> > Hi Mart-
>
> > I saw you were helping another guy with a bash script....hopefully you'll 
> > remember but i'm trying to modify it for my use.
>
> [...]
>
> > What I want to do is simply if the destination file exists, instead it 
> > creates an index number and appends that to the name.
>
> > If b.txt exists then a.txt will be renamed to b.txt.1, but if b.txt.1 
> > exists then it will be renamed to b.txt.2
>
> > I know I can do it with the script above but i'm a little lost on what I 
> > should be focusing on. This is my first time trying to modify a bash 
> > script, any help would be appreciative.
>
> Hello Curt,
>
> well I took a little time and tried to write something for you.
> I also send this to the newsgroup, as it's generally a better place to
> ask for help, than send me mail in private.
>
> My old code didn't fit your requirements imho, so i wrote some new.
> You didn't tell what you use to create the file curl, wget,...?
>
> #!/bin/bash
>
> set -f
> set -C
> shopt -s extglob
>
> max_check=10
>
> # list of files is in /tmp/list/ (as example)
> for file in $(find /tmp/list -type f); do
> #    echo "$file"
>     file="/tmp/out/${file##*/}" # output dir is /tmp/out/ (as example)
>     i=0
>     ext=
>     # start at max check - iterate backwards
>     # -> file found start new index
>     for ((x=max_check; x>=0; --x)); do
>         if [[ -e ${file}.${x} ]]; then
>             i=$x
>             ext=.$((i++))
>         break
>         fi
>     done
>     (
>     until command exec 3> "$file$ext"; do
>         ext=.$((i++))
>     done
>     # replace 'echo' with command of your choice
>     exec echo "$file$ext" >&3
>     ) 2>/dev/null    # you might not want to eleminate stderr
> done
>
> Best regards
>
> Mart

Thanks for posting this Mart.

I could get curl or wget to create the file, it really doesn't matter.
I suppose wget would be the best bet though since curl require an
additional package.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]