Aliases


Forum: Programming and Scripting
Topic: Aliases
started by: Zucca

Posted by Zucca on June 16 2006,02:59
Where ever I put my alias settings they wont work. But If I type it by hand to console it works just fine...

What to do?

Posted by mikshaw on June 16 2006,04:45
Where do you put them?
Generally they are put in .bashrc.  One thing you may want to check is whether or not you put them within the "if [ "$PS1" ]; then..." block. I haven't tested this to verify, but it's my understanding that anything inside this block will not apply to scripts.

Posted by Zucca on June 16 2006,07:00
Thanks. =)
I had put all my aliases to .bash_profile. ;)

In that way I can start vnc server for other accounts at startup? Do I get it right?

Posted by Zucca on June 16 2006,07:34
Nope.
Didn't work there either... :angry:

Posted by mikshaw on June 16 2006,14:13
I'm not sure I'm following you.  Are you sure you understand what Bash aliases are?  They don't really serve much purpose outside of Bash, and they don't apply to any other accounts (by this do you mean different linux users other than 'dsl'?).  

Maybe these aliases you have are specific to another program (vnc, for example)?  If this is the case then I can only make guesses unless you explain exactly what you're trying to accomplish.

Posted by pr0f3550r on June 16 2006,15:12
If you put all aliases in one file, eg .alias, then you can start your favourite apps from a bash script, lke this:
Code Sample

#!/bin/bash
#make sure you start this from aterm, not the root console

source $HOME/.alias
path/to/graphical-application &

Posted by Zucca on June 17 2006,10:59
Guys guys.

Maybe you understand my problem if I show part of my .bashrc file for you:
Code Sample
   alias ll="ls -lhaFC"
   alias reboot="sudo shutdown -r +5 "
   alias fastreboot="sudo shutdown -r now Brb. Sorry."


No. I do NOT use these aliases in scripts. I just want to add some aliases to make few things faster.

I wonder what I did wrong...
One thing more: dir alias seems to work. O.o If that works, why doesn't my aliases as they are definied just after dir alias?

Posted by mikshaw on June 17 2006,14:10
If you make changes to .bash_profile, they will not be applied until you either log out and back in again, or exit X and source /home/dsl/.bash_profile.

The .bash_profile file is run only for login shells, which in DSL means that it is run only once, when you first log in.  For this reason I recommend adding aliases to .bashrc instead, and source that file from .bash_profile.  In this way, every shell will have access to the aliases, and changes will not require re-sourcing for anything but the currently opened shell(s).

The suggestion made by the professor will work as well, though you will need to source the file from .bashrc AND source either .alias or .bashrc from .bash_profile in order to apply aliases to all shells. It is, however, a very useful method of setting alias groups, to have different sets of aliases at different times.

Posted by Zucca on June 17 2006,16:16
Yes. I got that too while reading some manuls... But the solution to this problem...
I'll try that soucing method...

Posted by Zucca on June 17 2006,16:41
Thanks guys. :D
source command worked just fine...

Is the source command just like 'include' in PHP?

Posted by mikshaw on June 17 2006,18:07
If include in php is like include in c, then yes.
Sourcing a file into a script is essentially the same as running the file, except it uses the currently active process rather than starting a new one....so it's extending the current script with the contents of an external file as if the external file was a part of the script.
It's very useful for utilizing things like functions and variables that are applied to multiple scripts.

Posted by pr0f3550r on June 18 2006,14:35
Quote (Zucca @ June 17 2006,12:41)
Is the source command just like 'include' in PHP?

In my view it's similar to virtual().
Posted by Zucca on June 18 2006,18:09
Ok. Thanks for the infos/advices. =)
Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.