Prev: Want to write a script to note specific IP addresses.
Next: get current timestamp in microseconds or milliseconds
From: Chris F.A. Johnson on 22 Oct 2009 22:59 On 2009-10-22, Ben Finney wrote: > Sivaram Neelakantan <nsivaram.net(a)gmail.com> writes: > >> That's right, I write scripts mostly for myself. And as mentioned, I >> pretty much expect the people using my scripts to NOT use spaces in >> the file names. :-) > > The disconnect in that is your scripts, even if you are the only one who > *uses* them directly, will inevitably be called upon to process > filenames generated by others. That's assuming, of course that you don't > suffer from OCD to the extent of checking the name of every single file > as it makes its way anywhere into your filesystem. > > The point being that it's far simpler, and never harmful, to make one's > scripts more robust in the face of easily-foreseen cases, by *always* > double-quoting any parameter expansion that might be a filename. There are times, at the command-line, when it is such a breath of fresh air to know that I don't have to deal with spaces in file names. This is usually in a section of the file tree that I have created myself (often web sites). Whn it comes to writing scripts, however, I always allow for the possibility of spaces or other pathological characters. -- Chris F.A. Johnson, author <http://shell.cfajohnson,com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
From: Sivaram Neelakantan on 23 Oct 2009 09:57 Ben Finney <bignose+hates-spam(a)benfinney.id.au> writes: > Sivaram Neelakantan <nsivaram.net(a)gmail.com> writes: > >> That's right, I write scripts mostly for myself. And as mentioned, I >> pretty much expect the people using my scripts to NOT use spaces in >> the file names. :-) > > The disconnect in that is your scripts, even if you are the only one who > *uses* them directly, will inevitably be called upon to process > filenames generated by others. That's assuming, of course that you don't > suffer from OCD to the extent of checking the name of every single file > as it makes its way anywhere into your filesystem. > > The point being that it's far simpler, and never harmful, to make one's > scripts more robust in the face of easily-foreseen cases, by *always* > double-quoting any parameter expansion that might be a filename. aye,aye, sir. Can the flogging stop for a few posts so that I can slink away? :-) sivaram --
From: Sivaram Neelakantan on 25 Oct 2009 08:20 Sivaram Neelakantan <nsivaram.net(a)gmail.com> writes: > Barry Margolin <barmar(a)alum.mit.edu> writes: [snipped 13 lines] err...I seem to be stuck with capturing the return code of each bg job. As mentioned before, I will be generating hundreds of graphs and pdfs. Pushing into the bg and putting a single wait in the main loop is what I have but I can't seem to get how to track the job and the associated status. What should I be doing? function gen_pdf () { local $fund_id=$1 local $amc=$2 cd $OUTDIR/$amc pdflatex ${amc}_${fund_id}.tex > /dev/null 2>&1 & #how should $! and $? be tracked together if [ $? -ne 0 ]; then else fi cd - } sivaram --
From: Marcel Bruinsma on 25 Oct 2009 15:33 Am Sonntag, 25. Oktober 2009 13:20, Sivaram Neelakantan a écrit : > Pushing into the bg and putting a single wait in the main loop > is what I have but I can't seem to get how to track the job and > the associated status. What should I be doing? You could use arrays, if your shell supports it (e.g. zsh, ksh, bash). pidlist=() # in gen_pdf pdflatex <parameters> & pidlist+=($!) # wait in loop exstat=() for ((i=1;i<=${#pidlist};i++)) do wait ${pidlist[$i]} exstat[$i]=$? done The actual syntax depends on the shell you use (as does index numbering; ksh starts at index 0, zsh at 1). Or, alternatively, you could use one associative array, with the process-ID as key, and the exit status as value. -- printf -v email $(echo \ 155 141 162 143 145 154 142 162 165 151 \ 156 163 155 141 100 171 141 150 157 157 056 143 157 155|tr \ \\\\) # Live every life as if it were your last! #
From: Bill Marcum on 25 Oct 2009 15:42
On 2009-10-25, Sivaram Neelakantan <nsivaram.net(a)gmail.com> wrote: > cd $OUTDIR/$amc > pdflatex ${amc}_${fund_id}.tex > /dev/null 2>&1 & ( pdflatex ${amc}_${fund_id}.tex > /dev/null 2>&1 echo ${amc}_${fund_id}.tex $? >> $logfile ) & > #how should $! and $? be tracked together > if [ $? -ne 0 ]; then > > else > > fi > cd - > } > > > > sivaram > -- |