In a shell script, I have a function afun
that was passed a few arguments.
I need another function that will help me find out if at least one of those arguments contains a given character which is not known a priori (but it could be any character like a
, 9
, *
, \
, |
, /
, (
, [
and so on, but not space
):
afun() {
# Some commands here...
testchar=... # here I have some logic which decides what character should be tested below
# Now, call another function to test if any of the args to "afun"
# contain the character in var "testchar".
# If it does, print "Found character '$testchar' !"
}
The proposed function should be compatible at least with Bash, Dash, Ash and ZSH - because I have a script that needs to run under different Linux distros (Ubuntu, Alpine Linux) installed in Docker containers, and I don't want to declare a dependency on a specific shell interpreter since not all those containers will necessarily have it installed.