|
-
Alias script symlink on ~/.profile
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.
Last edited by Kerms; 08-19-2012 at 02:20 AM.
-
-
 Originally Posted by Hector
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.
-
Similar Threads
-
By Melissa in forum Forum Assistance
Replies: 3
Last Post: 05-29-2012, 08:41 AM
-
By Darwin in forum General Linux
Replies: 1
Last Post: 04-25-2012, 09:28 PM
-
By ehansen in forum Linux-Howtos
Replies: 2
Last Post: 04-24-2012, 10:27 AM
-
By News in forum Linux News
Replies: 0
Last Post: 01-26-2012, 10:19 PM
-
By Fred in forum Linux News
Replies: 0
Last Post: 12-24-2011, 02:53 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Check out Linux Central for Linux software and other goodies!
» Recent Threads
» Stats
Members: 3,542
Threads: 3,912
Posts: 9,423
Top Poster: Fred (1,486)
Welcome to our newest member, dnacon
» Links
|
Bookmarks