UNIX alias question

Discussion in 'Mac Programming' started by Let's Sekuhara!, Jun 15, 2012.

  1. macrumors 6502

    Let's Sekuhara!

    Jun 30, 2008
    Hi, I'm new to UNIX and want to set up an alias called "trash" that will send files to ~/.Trash instead of deleting them like rm does.

    I've found multiple websites stating that a command such as:
    alias trash 'mv\!* ~/.Trash'
    will do just that.

    However when I run that command all I get is:
    -bash: alias: mv\!* ~/.Trash: not found
    Why? :confused:
  2. macrumors 68040

    Feb 2, 2008
    It works, in csh. Bash alias does not support arguments.
  3. thread starter macrumors 6502

    Let's Sekuhara!

    Jun 30, 2008
    Ah ha!
    Thank you for shedding light on that.
    Nothing I can do to work around that I suppose?
  4. subsonix, Jun 16, 2012
    Last edited: Jun 16, 2012

    macrumors 68040

    Feb 2, 2008
    Yes, you can create a function that you define in your ~/.profile that takes the arguments, then make the alias call that function, I have never done that my self though.

    But, to be honest it may be more straight forward to just create a small script that does what you want. This should do what that alias did, you can do more here as well if you want to, like suppress the error from "mv" and replace it with a custom error message if a file can't be found and so on.

    Test and run at your own risk. :)

    if [ $# -lt 1 ]
        echo "Usage: trash [filename]"
        exit 0
        for i in "$@"
            mv "$i" ~/.Trash
    If you have folder in your $PATH where you place your scripts, just put it there, after you 'chmod u+x' it.
  5. macrumors member

    Jun 4, 2009
    You could change your shell to tcsh and get the true BSD experience :)

    ctrl-click your user in the "Accounts" pref pane and choose advanced. Then you can enter the path to any shell you like (such as /bin/tcsh).

Share This Page