alias not working as expected [closed]
It's because the outer double quotes allow $1
to be evaluated by the shell when the alias is defined, so print $1
becomes plain print
:
$ alias file-types="find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u"
$ alias file-types
alias file-types='find . -type f | perl -ne '\''print if m/\.([^.\/]+)$/'\'' | sort -u'
Probably the simplest way to fix the quoting is to backslash-escape the $
:
print \$1 if m/\.([^.\/]+)$/
however I'd recommend using a shell function in place of an alias for cases like this - see for example In Bash, when to alias, when to script, and when to write a function?