I thought this was a weird one-off glitch at first, but now I've found a second completely different bash function with the same behavior, so I'm reaching out for help because it's driving me mad.
Context: I'm working on a Mac with ZSH as my shell. I have a few helper scripts in the form of shell functions to automate a few things I do regularly. Most of them require a parameter to be passed. That parameter is a 2 letter country code (AU, CA, UK, DE, etc). Most of them work just fine, but there are two functions that fail when CA
is passed as the parameter.
The error:
cat: illegal option -- A
usage: cat [-belnstuv] [file ...]
Notes while testing, applies to both functions:
- Confirmed directories exists.
- All other country codes work (US, UK, AU, DE, JP).
- Lowercase
ca
works. - Other random 2 letter strings ending with
A
work. - Other random 2 letter strings starting with
C
work. - Using just
A
also works, as intaillog A
.
Failing function 1, ran with: taillog CA
function taillog() {
local grey="1;30"
local red="1;31"
local green="1;32"
local yellow="1;33"
local cyan="1;36"
tail -f /Users/myUser/Sites/Country-"$1"/logs/error.log \
| GREP_COLOR="$green" grep -E --color=always --line-buffered "(\[php7?:info\])|$" \
| GREP_COLOR="$cyan" grep -E --color=always --line-buffered "(\[php7?:notice\])|$" \
| GREP_COLOR="$yellow" grep -E --color=always --line-buffered "(\[php7?:warn\])|(?i:warn(ing))|$" \
| GREP_COLOR="$red" grep -E --color=always --line-buffered "(\[php7?:error\])|(?i:error(s))|(?i:fatal)|$" \
| GREP_COLOR="$grey" grep -E --color=always --line-buffered "(?i:debug)|$"
}
Failing function 2, ran with findChanged CA 600
function findChanged() {
find /Users/myUser/Sites/Country-"$1"/public/wp-content/plugins -type f -cmin -"$2" -not -path "*/\.git/*" | more
}
All other country codes work as expected. What is it about CA
that causes cat
to complain? It's driving me batty.
cat
, but you're not showing any code usingcat
. Are you just trying to confuse us?cat
do support a-A
option, which would be the equivalent ofcat -vte
supported by yourcat
implementation according to its usage message.grep -E --color=always --line-buffered
is GNUgrep
syntax, not macos grep syntax.(?i:...)
is perl regex syntax, notE
xtended regex syntax.(set -o xtrace; taillog CA)
to see what happens.alias -g CA="2>&1 | cat -A"
, causing any input ofCA
to expand tocat -A
. That's what was causing my troubles. Removing that line allows the shell functions listed above to execute as expected.