Sponsored Content
Full Discussion: shopt -s nullglob
Top Forums Shell Programming and Scripting shopt -s nullglob Post 302254561 by msb65 on Tuesday 4th of November 2008 05:53:14 PM
Old 11-04-2008
shopt -s nullglob

Hi,

I am using BASH. In a directory there are files that match either of the following 2 patterns: [AST]*.L1A_[GL]AC* or S*.L1A_MLAC*

I would like to write a script that will include a for loop, where for each file in the directory, a certain function will be performed. For example:

for FILE in [AST]*.L1A_[GL]AC* S*.L1A_MLAC*; do
echo $FILE
done

The content of the directory will be random, and there are 3 potential scenarios: 1) Files of both patterns exist in the directory, 2) Only files of the 1st pattern exist, 3) Only files of the 2nd pattern exist. The last two scenarios are problematic as one of the patterns won't be matched, resulting in my script behaving oddly.

- I believe the way around this is to use the shopt -s nullglob option. Does anyone have any other ideas?

- MAIN QUESTION: Where in the code should I put the shopt -s nullglob and shopt -u nullglob? Of course the shopt -s nullglob should be set immediately before the the beginning of the for loop. But, can the shopt -u nullglob be immediately after the beginning of the for loop (ie):

shopt -s nullglob
for FILE in [AST]*.L1A_[GL]AC* S*.L1A_MLAC*; do
shopt -u nullglob
echo $FILE
done

OR after the conclusion of the for loop (ie):

shopt -s nullglob
for FILE in [AST]*.L1A_[GL]AC* S*.L1A_MLAC*; do
echo $FILE
done
shopt -u nullglob

The reason I ask is because I will of course have more complicated code within the for loop, and only want the shopt nullglob command to affect the pattern matching when calling the for loop.

Thanks for your help.

Mike
 

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash 'shopt' doubt

Hi, I am using bash shell's extended pattern matching. What tweak the following code needs in order to get the expected output? shopt -s extglob f="a@b@_c@d@_e" echo "${f/@(@|@_)/__}" My expected output is: a__b__c__d__e but the actual output is: a__b@_c@d@_e # that is, how to... (3 Replies)
Discussion started by: royalibrahim
3 Replies

2. Shell Programming and Scripting

Bash, Bourne, and nullglob

I have a script that start out with this: #!/sbin/sh Several things run. However I cannot get: shopt -s nullglob to run in Bourne. I get: shopt: not found So within the main script (after #!/sbin/sh at the top) I start bash with: bash and try to run what I need with: shopt -s... (2 Replies)
Discussion started by: crowman
2 Replies

3. UNIX for Advanced & Expert Users

Shopt -s histappend

What is the point of this? Whenever I close my shell it appends to the history file without adding this. I have never seen it overwrite my history file. # When the shell exits, append to the history file instead of overwriting it shopt -s histappend (3 Replies)
Discussion started by: cokedude
3 Replies
Astro::FITS::Header::AST(3pm)				User Contributed Perl Documentation			     Astro::FITS::Header::AST(3pm)

NAME
Astro::FITS::Header::AST - Manipulates FITS headers from an AST object SYNOPSIS
use Astro::FITS::Header::AST; $header = new Astro::FITS::Header::AST( FrameSet => $wcsinfo ); $header = new Astro::FITS::Header::AST( FrameSet => $wcsinfo, Encoding => 'FITS-IRAF' ); $header = new Astro::FITS::Header::AST( Cards => @cards ); DESCRIPTION
This module makes use of the Starlink::AST module to read the FITS HDU from an AST FrameSet object. It stores information about a FITS header block in an object. Takes an hash as an argument, with an array reference pointing to an Starlink::AST FramSet object. REVISION
$Id$ METHODS
configure Reads a FITS header from a Starlink::AST FrameSet object $header->configure( FrameSet => $wcsinfo ); Base class initialisation also works: $header->configure( Cards => @cards ); Accepts a reference to an Starlink::AST FrameSet object. If a specific encoding is required, this can be specified using the Encoding argument. Default is FITS-WCS if no Encoding is given. Note that not all framesets can be encoded using FITS-WCS. $header->configure( FrameSet => $wcsinfo, Encoding => "Native" ); If Encoding is specified but undefined, the default will be decided by AST. SEE ALSO
"Starlink::AST", "Astro::FITS::Header" AUTHORS
Alasdair Allan <aa@astro.ex.ac.uk>, Tim Jenness <t.jenness@jach.hawaii.edu> COPYRIGHT
Copyright (C) 2007-2011 Science and Technology Facilities Council. Copyright (C) 2001-2005 Particle Physics and Astronomy Research Council. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place,Suite 330, Boston, MA 02111-1307, USA perl v5.14.2 2012-06-30 Astro::FITS::Header::AST(3pm)
All times are GMT -4. The time now is 07:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy