LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 05-17-2012, 08:56 AM   #1
Ashotti
LQ Newbie
 
Registered: May 2012
Posts: 18

Rep: Reputation: Disabled
Question How to add lines to the file .cshrc


I need to add a line (to create an alias) to the file .cshrc: how can I do this?

As far as I understood I should do that from the C shell, but I am working with the bash shell.

Because I always use the bash shell, does it make sense to modify the .bashrc file as well?

I am sorry if the question seems a bit confusing, but I am not an expert with Linux and Ubuntu.

Thanks a lot!!
 
Old 05-17-2012, 09:24 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Hi Ashotti and welcome to LinuxQuestions!

Indeed, the file .cshrc is used by the C-shells upon login. If your default shell is /bin/bash you must add the alias to .bashrc. Some Linux distributions use a file named .alias, that in turn is sourced by .bashrc. For example, in my OpenSuSE box I have:
Code:
test -s ~/.alias && . ~/.alias || true
in my .bashrc, so that I can put the aliases in .alias and they will be available to my login shell as well. Notice that in bash the . (dot) is a built-in command which is the same as the source command, whereas the C-shells have source only.

The difference between sourcing and executing a script is that in the former the statements inside the script run in the current shell, so that all the variable, function and alias definitions are retained. In the latter the script starts (forks) its own process (subshell), all the definitions are local to the new process and they are lost upon exiting. This is the reason why all the configuration files like .cshrc or .bashrc are sourced and not executed.

Hope this helps.
 
1 members found this post helpful.
Old 05-17-2012, 03:44 PM   #3
Ashotti
LQ Newbie
 
Registered: May 2012
Posts: 18

Original Poster
Rep: Reputation: Disabled
Thank you for your answer!

I don't have a .alias file, or at least it doesn't appear when I type "ls -a" in the shell, so that I suppose that I have to add a line directly to the .baschrc file, but (sorry for the stupid question) how can I do that?

If I understood correctly, when I modify the .baschrc file, the change will apply every time that I start a shell, is that right?

Thansk again for your help!
 
Old 05-17-2012, 04:03 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by Ashotti View Post
I don't have a .alias file, or at least it doesn't appear when I type "ls -a" in the shell, so that I suppose that I have to add a line directly to the .baschrc file
Well, you can create it and add the suggested line, or check the content of your current .bashrc and see if there is something similar. Anyway, yes - the simplest thing is to add the alias definition in .bashrc itself.
Quote:
Originally Posted by Ashotti View Post
but (sorry for the stupid question) how can I do that?
Not a stupid question (an answer can be stupid): if you sit in front of your computer and it's running a desktop manager (usually GNOME in ubuntu) you can open a terminal and issue:
Code:
gedit $HOME/.bashrc
This will open a simple editor in its own window, you can make the changes, save and quit. Directly in the terminal (I mean without a graphical user interface) you can try the vi editor, but sincerely it's not something a novice is supposed to do.
Quote:
Originally Posted by Ashotti View Post
If I understood correctly, when I modify the .baschrc file, the change will apply every time that I start a shell, is that right?
Yes. Actually the login process is something more complicated. You may check the bash reference guide (here is the direct link to the Bash Startup Files paragraph) or the bash man page under the section INVOCATION for more details.
Take in mind that every change you make in a shell (defining an alias, a shell function or changing the value of an environment variable) is local to the current shell and it's lost when you close the shell session. In other words, settings made in a terminal don't reflect in other terminals. This is the reason why you need a file whose content is executed (actually sourced) every time you start a new shell session (that is every time you open a new terminal). Hope it's a bit more clear now!
 
Old 05-17-2012, 04:18 PM   #5
Ashotti
LQ Newbie
 
Registered: May 2012
Posts: 18

Original Poster
Rep: Reputation: Disabled
Again, thanks a lot!

Quote:
Well, you can create it and add the suggested line
yes, I did, now I have my bash_aliases file!

Quote:
you can open a terminal and issue:
Code:

gedit $HOME/.bashrc
yes, I use gedit, this time I just typed wrong the name .... -_-

Quote:
Hope it's a bit more clear now!
Yes, a lot! Again thank you, I fixed the problem and now everything is working as I wanted :-D
 
Old 05-17-2012, 04:20 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Well done! You're welcome!
 
  


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
[SOLVED] How to add characters and lines to file nobtiba Programming 12 02-13-2011 09:40 PM
Add comma to end of lines in text file Johng Programming 9 08-21-2010 05:15 AM
why to commit .cshrc "source .cshrc" file in every new shell session simer_anand88 Mandriva 3 10-23-2009 10:44 AM
Add lines to a file isra Debian 5 03-05-2007 07:22 AM
how to add lines to a .conf file richeyc Linux - Hardware 2 04-29-2006 04:25 PM


All times are GMT -5. The time now is 06:36 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration