foamSearch: make it work within a read-only directory

Patch contributed by Bruno Santos: https://bugs.openfoam.org/view.php?id=2928
This commit is contained in:
Chris Greenshields
2018-05-15 11:53:48 +01:00
parent bfe333ff64
commit 8fb5772b41

View File

@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@ -48,6 +48,7 @@ Searches the <directory> for files named <filename> and extracts entries with
Examples:
* Default ddtSchemes entries in the fvSchemes files in all tutorials:
foamSearch $FOAM_TUTORIALS fvSchemes ddtSchemes.default
* Relaxations factors for U in fvSolutions files in all tutorials:
foamSearch -c $FOAM_TUTORIALS fvSolution relaxationFactors.equations.U
USAGE
@ -75,19 +76,14 @@ esac
[ "$#" -eq 3 ] || error "Wrong number of arguments: expected 3, found $#"
[ -d "$1" ] || error "$1 is not a directory"
tmp=$(mktemp tmp.XXXXXX)
files=$(find "$1" -name "$2")
[ -n "$files" ] || error "No file $2 found in $1"
for f in $files
do
foamDictionary -entry "$3" "$f" 2>/dev/null >> "$tmp"
done
[ -s "$tmp" ] && \
sort "$tmp" | uniq $count | sed '/^[\t 1-9]*$/d' || \
foamDictionary -entry "$3" "$f" 2>/dev/null
done | \
sort | uniq $count | sed '/^[\t 1-9]*$/d' || \
echo "No keyword $3 found in $2 files"
rm "$tmp" 2>/dev/null
#------------------------------------------------------------------------------