0

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 in taillog 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.

7
  • 2
    You're saying you're on a Mac, you're using the linux tag, you're talking of bash functions and then saying you're using zsh, you're talking about scripts, but showing functions. Your error is from cat, but you're not showing any code using cat. Are you just trying to confuse us? Jun 23 at 15:03
  • 1
    FWIW, some implementations of cat do support a -A option, which would be the equivalent of cat -vte supported by your cat implementation according to its usage message. Jun 23 at 15:04
  • 1
    grep -E --color=always --line-buffered is GNU grep syntax, not macos grep syntax. (?i:...) is perl regex syntax, not Extended regex syntax. Jun 23 at 15:07
  • Try (set -o xtrace; taillog CA) to see what happens. Jun 23 at 15:11
  • 1
    I wasn't trying to confuse anybody. I was equally confused. It's why I posted. Turns out that one of my ZSH plugins, "common-aliases" was injecting a global alias, alias -g CA="2>&1 | cat -A", causing any input of CA to expand to cat -A. That's what was causing my troubles. Removing that line allows the shell functions listed above to execute as expected. Jun 23 at 15:38

1 Answer 1

3

Turns out that one of my ZSH plugins, "common-aliases" was injecting a global alias, alias -g CA="2>&1 | cat -A", causing any input of CA to expand to cat -A. That's what was causing my troubles. Removing that line allows the shell functions listed above to execute as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.