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.
testcharinstead ofc)echo -e), whereas zsh is intentionally incompatible with the standard (in places where its maintainers decided -- with some basis in fact -- that the standard enforces bad design decisions) unless running in non-default posix mode. That's not to say that writing scripts compatible with both zsh and POSIX-compliant shells can't be done, but it does mean that it requires a bit more care than the usual (ash+bash+ksh) practice of just complying with POSIX.localis not defined by POSIX -- if you're going for maximal compatibility, you'll want to do without.