This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hi Mike, I appreciate AND empathize with your comments about the pains of learning how to do create shell scripts from popular press books (although the O'Reilly are typically some of the best). I find myself in much the same boat... my scripting language of choice is Tcl (of Tcl/Tk) mainly since I was forced to learn it in order to use Tk. The good news is that the books I read on Tcl were chock full of useful examples that could be run as is and produce expected results and then modified to experiment. Anyway, there is a problem with the last script that I sent you. The 'if' clause is not correct. It should read: # Log results if $?; then echo $(date -u +'%b %d %T') $(basename $0)\[$$\]: Error writing ncdump output, exit status = $?" else echo $(date -u +'%b %d %T') $(basename $0)\[$$\]: FILE $1 rm -f $DIRS/pipencdump fi Steve pointed this out to me noting that 'if false; then' will always evaluate to false since false is actually a program: man false FALSE(1) User Commands FALSE(1) NAME false - do nothing, unsuccessfully SYNOPSIS false [ignored command line arguments] false OPTION DESCRIPTION Exit with a status code indicating failure. ... So, the first branch of the script as sent would never be executed. Also, it would be a good idea to check the exit status of each program that is run so that execution would not continue past such an error. In the spirit of this notion, I offer the following rewrite of ldmfile.sh: #!/bin/bash #--------------------------------------------------------------------- # # Name: ldmfile.bash # # Purpose: file an LDM product and log the receipt of the product # Note: modify the "log" file for a specific use! # # History: 20070412 - Created from example Bourne shell script # provided by Unidata # 20070416 - Modified by Tom at Unidata # #------------------------------------------------------------------------ # set log file LOG=/usr/local/ldm/MADIS_data/logs/MADIS_log exec >>$LOG 2>&1 # Create directory structure FNAME=$(basename $1) DIRS=$(echo $1 | sed s/$FNAME//) mkdir -p $DIRS # Write stdin to the designated file gunzip -cf > $DIRS/pipencdump if $?; then echo $(date -u +'%b %d %T') $(basename $0)\[$$\]: Error gunziping input, exit status = $?" exit fi # Create an ASCII version of the netCDF ncdump $DIRS/pipencdump > $1 if $?; then echo $(date -u +'%b %d %T') $(basename $0)\[$$\]: Error writing ncdump output, exit status = $?" exit fi # Success echo $(date -u +'%b %d %T') $(basename $0)\[$$\]: FILE $1 rm -f $DIRS/pipencdump # done exit Cheers, Tom **************************************************************************** Unidata User Support UCAR Unidata Program (303) 497-8642 P.O. Box 3000 address@hidden Boulder, CO 80307 ---------------------------------------------------------------------------- Unidata HomePage http://www.unidata.ucar.edu **************************************************************************** Ticket Details =================== Ticket ID: UKU-190526 Department: Support LDM Priority: Normal Status: Closed