[Top][All Lists]

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

FWD: About Bash Script

From: Mart Frauenlob
Subject: FWD: About Bash Script
Date: Mon, 15 Feb 2010 22:20:05 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20100111 Thunderbird/3.0.1

> -------- Original Message --------
> Subject:      About Bash Script
> Date:         Mon, 15 Feb 2010 10:39:25 -0600
> From:         Curt <address@hidden>
> To:   address@hidden
> 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,...?


set -f
set -C
shopt -s extglob


# 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)
    # start at max check - iterate backwards
    # -> file found start new index
    for ((x=max_check; x>=0; --x)); do
        if [[ -e ${file}.${x} ]]; then
    until command exec 3> "$file$ext"; do
    # replace 'echo' with command of your choice
    exec echo "$file$ext" >&3
    ) 2>/dev/null    # you might not want to eleminate stderr

Best regards


reply via email to

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