Alias script symlink on ~/.profile

H

Hector

Guest
I recently attempted to create an .alias script to run on calm window manager upon starting Rxvt. I dislike putting the commands in the profile script, however, because I prefer a more modular approach.

Here is what I did:

I created a bash script ~/.alias in my home directory, and then created a symbolic link to said script in $HOME/bin/ called salias. Then I created a small section in ~/.profile that executed salias. Salias is in my search path, so it executes whenever a loginshell is put forth:

Code:
#!/bin/sh
#.alias file, symlinked to by $PATH/bin/salias.
#pretty basic, but you understand.
alias ds='ls -l'
alias dsa='ls -lsa'

This way I get to keep my profile neat and clean, and the executable stays in my bin folder. Caution: make sure you take the adequate test measures before executing outside scripts.

Unfortunately, It appears that salias is generating the relevant commands, but the aliases are staying in the local namespace, and therefore are being destroyed when salias exits. I will try exporting the values with export when I get home. Will keep you updated.
 


I'm a bit confused on what you're doing:

Are you saying that salias is present in your PATH? Why not just refer it in your .bashrc?

If you put the aliases directly into .bashrc (or stored in a separate file, executed by .bashrc), you don't have to type sailias to the the aliases working.

And at least for me, in Debian, .profile is nothing more than a script referring to .bashrc.

(.profile is a simple script ran when you log in, directing each shell to their respective rc, and starting various other programs when you log in. It's a bad idea to put aliases in here because alias is a built-in command. )

Also, I think you're confusing $HOME with $PATH.
 
Unfortunately, It appears that salias is generating the relevant commands, but the aliases are staying in the local namespace, and therefore are being destroyed when salias exits.

Exactly. The solution is to put one alias in ~/.profile (or ~/.bashrc) instead of using a separate file:
Code:
alias salias='source ~/.alias'

But I'm not sure what you gain by making it separately executable. If you just want to keep things modular by having aliases in a separate file, that's fine, but you can still source it from .profile or .bashrc. That way you wouldn't have to manually execute it everytime you open a shell.

I do something vaguely similar. I have one .bashrc file that I use on ALL machines I can access. And it looks for and sources ~/bin/local.bashrc if it's present. That makes it easier for me to update the common part across platforms.
 
This is similiar to that which I desired, except I also wanted to keep the executable in ~/bin, but still use $HOME for configuration. Since .alias, in my view, is considered configuration, I referenced Salias in my .profile. Salias, of course, links to .alias. I am thinking, however, that I might go with the otherbapproach. Thanks.
 

Members online


Latest posts

Top