You are not logged in.

#1 2007-08-16 22:53:06

FeatherMonkey
Member
Registered: 2007-02-26
Posts: 313

A question about bash alias with rm

As said I was trying to make rm remove to trash which I've achieved like this.

function mod_rm()
{
kfmclient move $* trash:/
}
alias rm="mod_rm"

Now I got told off for modifying the rm alias said bad practices, it was bought to my attention this may cause some scripts to move tmp files to trash.

So my question is this bad practices?
And if it is how could I achieve the above which is make the rm command move rubbish to trash?

Offline

#2 2007-08-17 03:51:09

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: A question about bash alias with rm

Personally I'd create the new function (call it trash, for example) and make a habit of using that function instead of rm, saving rm for when I'm really serious. :-)  However, I wouldn't worry about "bad practice"; try it and if you find mysterious tmp files showing up in your trash, you can worry about it then. I would personally think its better to have files I don't care about moved to trash than to have important files wiped away forever.

Plus, if you put that alias in your .bash_profile instead of your .bashrc, it should only be sourced for interactive sessions anyway, which means scripts won't touch it. You could even enforce this by testing in your mod_rm function to ensure you are in a login shell (I can't remember the command, I think you have to check an environment variable of some sort).

Dusty

Offline

#3 2007-08-17 11:10:47

FeatherMonkey
Member
Registered: 2007-02-26
Posts: 313

Re: A question about bash alias with rm

Thanks Dusty that was my conclusion in the end, pretty much how I replied, and you're are very correct, I was more trying to protect the rm command. I know I should alias it to something like trash, but I'd still have rm in the path.

I've yet to notice anything so for my usage it seems fine, but I guess other people will have to judge for themselves, thanks for the tip about .bash_profile.

Now that I know its bad practice, just need to make sure its not any more, but for this example I'll stick to it. wink

Offline

#4 2007-08-17 13:49:57

FeatherMonkey
Member
Registered: 2007-02-26
Posts: 313

Re: A question about bash alias with rm

On further looking into I discovered its possible to escape in bash scripts
/rm
Though I did try and from reading the man bash it implys that only interactive shell will do alias expansion and not script. I have checked it and by all accounts it seems to be the case, a script with rm will ignore my alias.

Can someone confirm or deny does bash script do alias expansion from bashrc? I think it doesn't.

Offline

Board footer

Powered by FluxBB