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
OCAMLCP(1)						      General Commands Manual							OCAMLCP(1)

NAME
ocamlcp - The Objective Caml profiling compiler SYNOPSIS
ocamlcp [ ocamlc options ] [ -p flags ] filename ... DESCRIPTION
The ocamlcp command is a front-end to ocamlc(1) that instruments the source code, adding code to record how many times functions are called, branches of conditionals are taken, ... Execution of instrumented code produces an execution profile in the file ocamlprof.dump, which can be read using ocamlprof(1). ocamlcp accepts the same arguments and options as ocamlc(1). OPTIONS
In addition to the ocamlc(1) options, ocamlcp accepts the following option controlling the amount of profiling information: -p letters The letters indicate which parts of the program should be profiled: a all options f function calls : a count point is set at the beginning of each function body i if ... then ... else: count points are set in both then and else branches l 0 loops: a count point is set at the beginning of the loop body m match branches: a count point is set at the beginning of the body of each branch of a pattern-matching t try ... with branches: a count point is set at the beginning of the body of each branch of an exception catcher For instance, compiling with ocamlcp -pfilm profiles function calls, if ... then ... else ..., loops, and pattern matching. Calling ocamlcp(1) without the -p option defaults to -p fm meaning that only function calls and pattern matching are profiled. Note: due to the implementation of streams and stream patterns as syntactic sugar, it is hard to predict what parts of stream expressions and patterns will be profiled by a given flag. To profile a program with streams, we recommend using ocamlcp -p a. SEE ALSO
ocamlc(1), ocamlprof(1). The Objective Caml user's manual, chapter "Profiling". OCAMLCP(1)
All times are GMT -4. The time now is 03:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy