LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to add lines to the file .cshrc (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-add-lines-to-the-file-cshrc-945511/)

Ashotti 05-17-2012 07:56 AM

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!!

colucix 05-17-2012 08:24 AM

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.

Ashotti 05-17-2012 02:44 PM

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!

colucix 05-17-2012 03:03 PM

Quote:

Originally Posted by Ashotti (Post 4681163)
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 (Post 4681163)
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 (Post 4681163)
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! :)

Ashotti 05-17-2012 03:18 PM

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

colucix 05-17-2012 03:20 PM

Well done! :) You're welcome!


All times are GMT -5. The time now is 01:45 AM.