Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: alias with a parameter



On Wed, Apr 14, 2021 at 4:10 AM zzapper <zsh@xxxxxxxxxxxxxx> wrote:
>
> Am using a case statement as a ***visually elegant way*** of excluding a
> potentially changing list of Global Aliases from being automatically
> expanded

Sorry, you're using this ... where? ... to achieve that?

>    if [ $# -gt 0 ] ; then
> case $1 in
>     [A-Z] | V<-> | G* ) ;;
>   *) echo "Yes expand"
>    ;;
> esac
>    fi

It's generally preferable to use [[ ... ]] instead of [ ... ] because
"[" is just another name for "test" and "]" is just one of its
arguments, whereas "[[" and "]]" are syntax tokens with parsing rules
for what appears between them.  However, since you're comparing
numbers, you could use (( $# > 0 )) here.

However you really don't need that test at all:

case "$1" in
  ("") false;;
  ([A-Z]|V<->|G*);;
  (*) echo "Yes expand";;
esac

You probably don't even need the first "false'' case, I threw it in
just to keep the same $? as your original "if".

case "$1" in
  (|[A-Z]|V<->|G*);;
  (*) echo "Yes expand";;
esac




Messages sorted by: Reverse Date, Date, Thread, Author