Vin
Vin

Reputation: 62

Making an alias for Temp Remove

I want to make an alias in bash to do this: mv -vi SomeFile_or_Directory /tmp and use it instead of dangerous rm

I'm using a script(placed in /usr/bin/) to do this now, but I'd like to use an alias instead.

the script:

#!/bin/bash
for i in $@
do
   mv -vi $i /tmp
done

I tried alias t='for i in $@;do;mv -vi $i /tmp;done' but it didn't work.

How do I solve this?

Upvotes: 0

Views: 42

Answers (2)

Nue
Nue

Reputation: 49

In this case an alias won't work; cuz aliases don't support control flow completely.

Put the function or the script in your .profile. That way you can access the command from other shells, e.g. zsh.

Upvotes: 1

chepner
chepner

Reputation: 531948

Use a function instead:

t () {
    for i in "$@"; do
        mv -vi -- "$i" /tmp
    done
}

Upvotes: 2

Related Questions