part of shnell – a source to source compiler enhancement tool
© Jens Gustedt, 2017
Utilities for shell level regexp matching.
Coding and configuration
The following code is needed to enable the sh-module framework.SRC="$_" . "${0%%/${0##*/}}/import.sh"
Imports
The following sh
-modules are imported:
Details
We provide environment variables for certain tools.
export SED=${SED:=sed}
export SEDU=${SEDU:=-u}
export CAT=${CAT:=cat}
if [ ! "${PAGER}" ] ; then
PAGER=`whereis -b "less"`
if [ "${PAGER}" != "less:" ] ; then
export PAGER="less -R"
else
PAGER=`whereis -b "more"`
if [ "${PAGER}" != "more:" ] ; then
export PAGER="more"
else
export PAGER="${CAT}"
fi
fi
fi
The matching we do requires UTF-8 capacities, so we try to set LC_LANG
to a UTF-8 locale.
Declared functions
match
: Check if string $2 matches regexp $1
This uses shell pattern matching and can be used more simply than the shell’s case
construct on which it is built. It can be used as simple prefix conditionals
```cpp match “*[a-z]*” “${id}" || echo "${id} is not an identifier”
or in if
-then
-else
constructs
#if match “*[a-z]*” “${id}" ; then echo "${id} is not an identifier” fi
hasBlank
: Test if a list given as an argument has more than one member
replace
: In $1, replace the occurences of string $2 by the string $3
The modified string is returned in the variable rplret
. ### sed3
: A sed that reads the commands from fd 3 As usual this reads the text to be processed from stdin
. ### sed2
: A sed that reads the commands from $1 and the text from the remaining arguments