LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Command Aliases??? (https://www.linuxquestions.org/questions/slackware-14/command-aliases-462944/)

UFCfighter 07-11-2006 08:38 AM

Command Aliases???
 
Does anyone know where command aliases in SLACKWARE go? Using the alias command, aliases are gone after logout. Where do global aliases vs. user aliases placed? I would appreciate the help, thanks.

piete 07-11-2006 08:46 AM

Local aliases should be placed in ~/.bashrc and global ones in /etc/bashrc

- Piete

UFCfighter 07-11-2006 08:48 AM

Thanks, but...
 
Thanks for the reply, but I don't have a .bashrc in my entire system. Is this something that I can just create, or could aliases be placed elsewhere? Thanks.

piete 07-11-2006 08:54 AM

You should just be able to create one and have it working, bash is very easy going =)

binary_y2k2 07-11-2006 08:56 AM

If your login shell is bash you should have it in your home dir and a system one in /etc (maybe called bash.bashrc) if not loon in /etc/profile

UFCfighter 07-11-2006 08:57 AM

I created .bashrc but...
 
I created the files in a few places to try it out. First, I created etc/.bashrc. Then I tried home/user/.bashrc, usr/.bashrc, and a few other places. None of them worked.

UFCfighter 07-11-2006 09:02 AM

etc/profile
 
Thanks for the help. There is a file etc/profile, and I tried adding ALIAS XX="XX -X", but it didn't work. I also tried xx = "xx -x" but still didn't work.

binary_y2k2 07-11-2006 09:04 AM

in the /etc dir the file is called either /etc/bashrc (no leading dot) or /etc/bash.bashrc

What is the cpntense of your /etc/profile file?

piete 07-11-2006 09:16 AM

Ahh, I see, we still have some problems.

Basically ya gotta set up the system ...

The system is as follows:

/etc/profile --> $HOME/.bash_profile --> $HOME/.bashrc --> /etc/bashrc

If you don't already have $HOME/.bash_profile, then create it and make sure it contains the following:

Code:

# Source local bashrc
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

Then, in $HOME/.bashrc make sure the following exists:

Code:

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

This will preserve your aliases when you su from user, and allow alises to crop up when you use an xterm.

I realise it's not exceptionally clear, but the explanation is long and i'm tired =)
- Piete.

UFCfighter 07-11-2006 09:18 AM

no bashrc, .bashrc, bash, .bash, etc...
 
no bashrc, .bashrc, bash, .bash, etc...

theNbomr 07-11-2006 09:22 AM

You probably aren't using bash. When you type at a commandline

echo $SHELL

what do you see?

If you are using csh or tcsh, then your shell startup script is .cshrc
You can add aliases there.

eg.
alias dir 'ls -lash'

(Note different syntax from Bourne shells.)

--- rod.

sbabaro 07-11-2006 09:24 AM

/etc/profile.d
 
I have aliases working with bash with an executable file that I called aliases.sh in /etc/profile.d dir
then you need to be sure that your aliases will be loaded anyway, either if your shell is a login one or not.
To solve this I create .bashrc in my home
[code]


[ -f /etc/profile ] && . /etc/profile
[ -f /etc/bashrc ] && . /etc/bashrc

[\code]

It executes the files in /etc/profile.d, loading also your aliases

piete 07-11-2006 09:51 AM

Quote:

no bashrc, .bashrc, bash, .bash, etc...
You can make them, there is no problem doing that. If you don't have the file ... write it.

I like sbabaro's solution to aliases - very neat, very Slackware.

UFCfighter 07-11-2006 09:59 AM

I'm definitely using bash
 
I'm using bash, but I don't have the files that people say I should have. This was a straight install of Slackware 10.2.

sbabaro 07-11-2006 10:19 AM

create it!
 
as piete said, create it!

The only files that you have in a fresh Slack is /etc/profile and /etc/profile.d (with several scripts inside)
The others you need to create by yourself
Use your favorite editor and write it down the file using one of the solution shown in this thread


All times are GMT -5. The time now is 11:13 AM.