Question

How should one use globbing inside an alias in tcsh? For instance, say we want an alias which moves all files which begin with a given string to a specific folder:

alias mv_to_trash 'mv !\:1* ~/trash' does not move all files starting with jk to trash:

mv_to_trash jk

yields

mv: No match. But there are two files, jk1 and jk2, which should match.

Was it helpful?

Solution

This is not a safe approach. Please don't rely on the alias itself to expand wildcards, as doing so will violate the principle of least astonishment. What if an unaware user will call an alias which will do unexpected globbing?

Much, much better is to let the alias take an arbitrary number of arguments

alias mv_to_trash 'mv \!* ~/trash'

and to call it by providing an explicit wildcard, if desired:

mv_to_trash jk*

This is both safer and more precise. It also offers a greater control and flexibility: you can use other pattern-matching operators, if you will, without changing the alias definition.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top