Prev: Automatically rename a downloaded file by curl to avoid filename conflict.
Next: stratifying values in a file ...
From: Stephane CHAZELAS on 7 Feb 2010 04:45 2010-02-07, 12:58(+08), Hongyi Zhao: > On Thu, 4 Feb 2010 12:18:29 +0000 (UTC), Stephane CHAZELAS > <stephane_chazelas(a)yahoo.fr> wrote: > >>url=http://www.google.com/ >>file=myfile >>( >> set -C >> ext= n=0 >> until command exec 3> "$file$ext"; do >> ext=.$((++n)) >> done >> exec curl "$url" >&3 >>) > > The above code will give annoying output like this: > > line 15: myfile: cannot overwrite existing file. > > How can I suppress these output? until { command exec 3> "$file$ext"; } 2> /dev/null; do -- St�phane
From: Stephane CHAZELAS on 7 Feb 2010 08:27 2010-02-07, 20:28(+08), Hongyi Zhao: > On Sun, 7 Feb 2010 09:45:21 +0000 (UTC), Stephane CHAZELAS > <stephane_chazelas(a)yahoo.fr> wrote: > >>until { command exec 3> "$file$ext"; } 2> /dev/null; do > > Good, thanks a lot. It does the trick. > > BTW, why cann't I use the following one: > > {until command exec 3> "$file$ext"; } 2> /dev/null; do [...] First, because, to be recognised as such the "{" keyword must be followed by a blank, and then, the until is part of a "until, do, done" sequence. {...} is group of commands, the until,do,done would be unfinished in the {...}. You could do: { until ...; do wget... done } 2> /dev/null or simply: until ...; do wget... done 2> /dev/null but then, the stderr of wget would also be redirected to /dev/null, which is probably not what you want. -- St�phane
From: Stephane CHAZELAS on 8 Feb 2010 12:52 2010-02-08, 15:02(+08), Hongyi Zhao: > On Thu, 4 Feb 2010 12:18:29 +0000 (UTC), Stephane CHAZELAS > <stephane_chazelas(a)yahoo.fr> wrote: > >>url=http://www.google.com/ >>file=myfile >>( >> set -C >> ext= n=0 >> until command exec 3> "$file$ext"; do >> ext=.$((++n)) >> done >> exec curl "$url" >&3 >>) > > I've another issue on the above code: > > When I run it for the first time, I'll obtain a file with the name > myfile. My issue is: the initial value of ext should be _.0_, so I > think the above script should name the output as myfile.0. Any hints > on this? It shouldn't be that hard to figure it out by yourself. url=http://www.google.com/ file=myfile ( set -C n=0 until { command exec 3> "$file.$n"; } 2> /dev/null; do n=$(($n + 1)) done exec curl "$url" >&3 ) -- St�phane
From: Stephane CHAZELAS on 9 Feb 2010 16:16
2010-02-09, 10:43(+08), Hongyi Zhao: [...] >>>>url=http://www.google.com/ >>>>file=myfile >>>>( >>>> set -C >>>> ext= n=0 >>>> until command exec 3> "$file$ext"; do >>>> ext=.$((++n)) >>>> done >>>> exec curl "$url" >&3 >>>>) [...] > My poor English. In fact, I want to know why your original code will > name the first downloaded file as myfile instead of myfile.0. > According to my understanding, it should also name the first > downloaded file as myfile.0 just as the below code does. Any hints? [...] You could try to add a "set -x" at the top, to see what happens. -- St�phane |