oachim Backes wrote:
Tim wrote:
On Mon, 2008-12-01 at 14:49 +0700, Yunus wrote:
Is there other way to make my custom alias (put in ~.bash_profile) work?
Just curious, but do they work if you put them in "~/.bashrc"?
Or in /etc/bashrc.
Unfortunately, exporting aliases is not supported by bash (neither in /etc/profile nor ~/.bash_profile) :-(
No ! that's not right ! Of course it is supported. Aliases can be defined anywhere /etc/bashrc, /etc/profile, /etc/profile.d/*, ~/.bashrc, ~/.bash-profile ie: in any of the rc files.
Where exactly you put it in, defines whether it would be defined system-wide (in the '/etc/' files), for all bash instances (including scritpts) for a particular user (in the ~/.bashrc) or only for login shells for a particular user (in ~/.bash_profile).
Yunus: After adding the aliases to the file, you need to 'source' it into the current bash session to active the alias:
[steve@laptop ~]$ echo 'alias l="ls -al"' >> ~/.bash_profile [steve@laptop ~]$ source .bash_profile # or simply ". ~/.bash_profile" [steve@laptop ~]$ l
regards, - steve
On Mon, 2008-12-01 at 11:27 +0000, Steve wrote:
Unfortunately, exporting aliases is not supported by bash (neither
in
/etc/profile nor ~/.bash_profile) :-(
No ! that's not right ! Of course it is supported. Aliases can be defined anywhere /etc/bashrc, /etc/profile, /etc/profile.d/*, ~/.bashrc, ~/.bash-profile ie: in any of the rc files.
These files are 'eval'ed, so their contents are executed in the context of the current shell.
A simple test shows that aliases are not exported:
[poc@bree:~] alias foo='ls -ld' [poc@bree:~] foo drwxr-xr-x 236 poc poc 20480 2008-12-01 01:07 . [poc@bree:~] bash [poc@bree:~] foo bash: foo: command not found
poc
On Mon, Dec 01, 2008 at 08:40:43AM -0430, Patrick O'Callaghan wrote:
On Mon, 2008-12-01 at 11:27 +0000, Steve wrote:
Unfortunately, exporting aliases is not supported by bash (neither
in
/etc/profile nor ~/.bash_profile) :-(
No ! that's not right ! Of course it is supported. Aliases can be defined anywhere /etc/bashrc, /etc/profile, /etc/profile.d/*, ~/.bashrc, ~/.bash-profile ie: in any of the rc files.
These files are 'eval'ed, so their contents are executed in the context of the current shell.
A simple test shows that aliases are not exported:
[poc@bree:~] alias foo='ls -ld' [poc@bree:~] foo drwxr-xr-x 236 poc poc 20480 2008-12-01 01:07 . [poc@bree:~] bash [poc@bree:~] foo bash: foo: command not found
If I recall correctly, /etc/profile, /etc/profile.d/*, and ~/.bash_profile are only eval'd in an interactive (login) shell. You probably want to place your alias in ~/.bashrc so it will be used in all shells.
Working manually, could also define foo as a function instead of an alias, and then export it:
[pfrields@localhost ~]$ foo() { ls -ld; } [pfrields@localhost ~]$ foo drwxr-xr-x 193 pfrields pfrields 12288 2008-12-01 09:00 . [pfrields@localhost ~]$ export -f foo [pfrields@localhost ~]$ bash [pfrields@localhost ~]$ foo drwxr-xr-x 193 pfrields pfrields 12288 2008-12-01 09:00 . [pfrields@localhost ~]$ exit
On Mon, 01 Dec 2008 08:40:43 -0430 "Patrick O'Callaghan" pocallaghan@gmail.com wrote:
On Mon, 2008-12-01 at 11:27 +0000, Steve wrote:
Unfortunately, exporting aliases is not supported by bash (neither
in
/etc/profile nor ~/.bash_profile) :-(
No ! that's not right ! Of course it is supported. Aliases can be defined anywhere /etc/bashrc, /etc/profile, /etc/profile.d/*, ~/.bashrc, ~/.bash-profile ie: in any of the rc files.
These files are 'eval'ed, so their contents are executed in the context of the current shell.
A simple test shows that aliases are not exported:
[poc@bree:~] alias foo='ls -ld' [poc@bree:~] foo drwxr-xr-x 236 poc poc 20480 2008-12-01 01:07 . [poc@bree:~] bash [poc@bree:~] foo bash: foo: command not found
poc
After puting alias commands in bash.rc or profile.rc you have to run "bash" (whithout"") at the prompt. Then the aliases work henk
On Mon, 2008-12-01 at 16:13 +0100, Henk Breimer wrote:
On Mon, 01 Dec 2008 08:40:43 -0430 "Patrick O'Callaghan" pocallaghan@gmail.com wrote:
On Mon, 2008-12-01 at 11:27 +0000, Steve wrote:
Unfortunately, exporting aliases is not supported by bash (neither
in
/etc/profile nor ~/.bash_profile) :-(
No ! that's not right ! Of course it is supported. Aliases can be defined anywhere /etc/bashrc, /etc/profile, /etc/profile.d/*, ~/.bashrc, ~/.bash-profile ie: in any of the rc files.
These files are 'eval'ed, so their contents are executed in the context of the current shell.
A simple test shows that aliases are not exported:
[poc@bree:~] alias foo='ls -ld' [poc@bree:~] foo drwxr-xr-x 236 poc poc 20480 2008-12-01 01:07 . [poc@bree:~] bash [poc@bree:~] foo bash: foo: command not found
poc
After puting alias commands in bash.rc or profile.rc you have to run "bash" (whithout"") at the prompt. Then the aliases work
You can do that if you want, but you'll be executing an extra shell for no reason, i.e. you're running a new shell as a child of the original shell.
Better is "exec bash" (which replaces the current shell with a new image, including initialization), or ". .bashrc" (which makes the current shell re-evaluate the contents of .bashrc). I tend to prefer the first as it's easier to type and gets all the initialization stuff in one go.
It's essential to understand this stuff if you ever want to do any Shell programming.
poc