LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-04-2006, 09:36 AM   #1
Four
Member
 
Registered: Aug 2005
Posts: 298

Rep: Reputation: 30
where should I put an alias


I would like to launch a program with specific parameters quite often and thus I would like to make an "alias" so it happens by default.

Where should I put it so I don't have to type it in myself in the terminal? Also where may I put costum variables to store strings so I may reference in variable names only?

Thank you.
 
Old 11-04-2006, 09:45 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
The "info bash" manual has information on the startup scripts, ~/.profile, ~/.bash_login, ~/.bash_profile:
Quote:
Invoked as an interactive login shell, or with `--login'
........................................................

When Bash is invoked as an interactive login shell, or as a
non-interactive shell with the `--login' option, it first reads and
executes commands from the file `/etc/profile', if that file exists.
After reading that file, it looks for `~/.bash_profile',
`~/.bash_login', and `~/.profile', in that order, and reads and
executes commands from the first one that exists and is readable. The
`--noprofile' option may be used when the shell is started to inhibit
this behavior.
.

The ~/.bashrc script is executed every time a non-login shell is started. The ~/.profile script may source the ~/.bashrc script.

You set variables like this:
export EDITOR=/usr/bin/vim

The export built in command adds the variable to the environment. Otherwise the definition is gone after the shell completes.

Quote:
I would like to launch a program with specific parameters quit often
Consider a wrapper script that calls the program with the options you want. You could put it in ~/bin/. Add ~/bin/ to your path in the bash startup script, e.g. ~/.profile.
If you add it to the front, then it will be searched first:
export PATH=$HOME/bin:$PATH
 
Old 11-04-2006, 09:56 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
In this post, I'm assuming you're using the bash shell. This is typical on most Linux systems. To check it, use the command "echo $SHELL". This will tell you what shell you are using.

If you only want to access the alias from one user account, the best place is probably in the .bashrc file in your HOME directory. This file is read each time a shell is started. You can put your variables here too. If you want shell variables available in programs you launch from the shell, make sure you export them, else just a regular var=value will suffice.

If you want your aliases/variables available for all users on the system, edit the /etc/profile file, and put them there. Settings in this file get applied to shells for all users.

There are a few more places you can put these things. Sometimes the .bashrc file will contain a line something like this:
Code:
. ~/.bash_aliases
...which simply tells the shell to read instructions from the file ~/.bash_aliases. Ubuntu has this command in the default .bashrc (with a little check to make sure the file exists first), but it is commented out. Personally, I use the .bash_aliases file for all my aliases because I fond it neater to keep all the alias statements together. It's a matter of personal preference.

There are a few more places you might choose to put these sorts of commands, like ~/.bash_profile. read the bash manual page (FILES section) for a more detailed list of what files are read and when.

One note of caution: be a little bit careful when editing these file because you could make changes which make it difficult to start a new shell, the canonical example of this is someone naughtily adding "logout" to the .bashrc file, which closes the shell as soon as it starts...

What I usually do when editing the .bashrc is save the changes, then try to open a new terminal while the original one is still open. This just ensures that you've not made a typo or something which might cause a problem. It's very unlikely you'll do anything bad. I think I messed up like this once, but it's a good habit anyhow.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IP alias? Machine name alias? JohnLocke Linux - Newbie 4 01-16-2008 12:21 PM
Alias question (2 commands for one alias) gflores Linux - Newbie 3 01-21-2006 12:40 AM
where I put the alias?? VemeC Slackware 4 06-26-2004 12:39 AM
where to put global alias' true_atlantis Slackware 4 12-25-2003 02:31 PM
alias(es) Tinkster Slackware 3 06-21-2002 06:25 AM


All times are GMT -5. The time now is 08:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration