From: Hongyi Zhao on
On Thu, 4 Feb 2010 10:57:07 +0000 (UTC), Stephane CHAZELAS
<stephane_chazelas(a)yahoo.fr> wrote:

>No, those are subject to race conditions, use set -C,

I'm a newbie of bash/shell programming. What do you mean by saying
*race conditions*? Could you please give me some more hints?

>redirections (no -o in curl or -O- in wget).
>
>(
> set -C
> ext= n=1
> until command exec 3> "$file$ext"
> ext=.$((++n))
> done
> exec curl ... >&3
>)

Could you please give the complete code segment for my issue?

Thanks in advance.
--
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
From: Seebs on
On 2010-02-04, Hongyi Zhao <hongyi.zhao(a)gmail.com> wrote:
> I'm a newbie of bash/shell programming. What do you mean by saying
> *race conditions*? Could you please give me some more hints?

A "race condition" is a case where other things happening at the same
time could cause something to fail. For instance, consider the simple
test:

if [ ! -e mydir ]; then
mkdir mydir
fi

This seems like it should create "mydir" only if there is not currently
anything named "mydir". However, it is not so. The [ ! -e mydir ] executes,
and then the shell executes mkdir. Other programs can do things between
them; for instance, another program could create a file named "mydir" after
the [ command has run, but before the mkdir has run, and then mkdir will
fail.

Similarly:

if [ -d mydir ]; then
cd mydir
fi

may fail unexpectedly, because "mydir" could be deleted between the [ and
the cd.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Rikishi42 on
On 2010-02-04, Hongyi Zhao <hongyi.zhao(a)gmail.com> wrote:

> When I download a file by curl, I use -o switch to write the file as a
> local file, say, myfile. The issue is: if a file with the same
> filename already exists in the target folder, the original file will
> be overwrited. So, I want to rename this downloaded file to something
> like this: myfile.1 in order to avoid filename conflict in the above
> case; in gerneral, if myfile.1 also has already exists in the
> destination folder, use myfile.2 as the filename for the curl's
> output; and so on ...
>
> Any hints for the above purpose?

Why bother ? Why not just put date and time in the file's name?

get download date in a variable (not technically indispensable).
OUTPUT_NAME=`date "+%Y%m%d_%H%M%S"`

Then, eighter use:
curl -o $OUTPUT_NAME

or, if you can't specify a download name:
curl -o
mv myfile $OUTPUT_NAME





--
Any time things appear to be going better, you have overlooked
something.
From: Hongyi Zhao on
On 04 Feb 2010 20:56:33 GMT, Seebs <usenet-nospam(a)seebs.net> wrote:

>A "race condition" is a case where other things happening at the same
>time could cause something to fail. For instance, consider the simple
>test:
[snipped]

Good, thanks a lot.
--
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
From: Hongyi Zhao on
On Fri, 5 Feb 2010 01:24:10 +0100, Rikishi42
<skunkworks(a)rikishi42.net> wrote:

>Why bother ? Why not just put date and time in the file's name?
>
>get download date in a variable (not technically indispensable).
> OUTPUT_NAME=`date "+%Y%m%d_%H%M%S"`
>
>Then, eighter use:
> curl -o $OUTPUT_NAME
>
>or, if you can't specify a download name:
> curl -o
> mv myfile $OUTPUT_NAME

If the system's time has happened to be changed by some virus, this
method maybe fail to generate the _unique_ OUTPUT_NAME.
--
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.