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, re: > Hmmm. Looks like my version of Bash and yours are different. I am not sure that it makes any difference, but ldmfile.sh uses Bourne shell syntax (#!/bin/sh), not bash. > Mine has no "data" command, Your follow-up email showed that you noticed that this should be 'date' not 'data'... > "basename" appears to need an operand > (apparently $1 just isn't good enough. I don't know why not!) and "sed" > is behaving in ways I don't understand. I think this is because your declaration of which shell to use was not the first line of your script. > Other than that, I'm having a fine night! (??). :-) > I've attached the log > file for the script for clarification. > > Can you make any suggestions regarding this confusing Bash script? The following is my slightly modified version of your script. I have verified that this works nicely on my Fedora Core 6 development machine at home: #!/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 # #------------------------------------------------------------------------ # 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 and log its filing echo $(date -u +'%b %d %T') $(basename $0)\[$$\]: FILE $1 cat > $1 # Log errors if false; then logger -p local0.error "Error writing input file, exit status = $?" fi # done exit 0 The changes I made were: - specify the shell to use in the first line of the script - remove the '-' before the 's' in the sed line (i.e., 'sed s/$FNAME//' not 'sed -s/$FNAME//') - changed the message that logger will write on 'cat > $1' failure (not tested) > Thanks No worries. I think you should be on your way now... 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