LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Create Default Path When Terminal Is opened (https://www.linuxquestions.org/questions/linux-newbie-8/create-default-path-when-terminal-is-opened-898747/)

hitmen 08-22-2011 07:18 AM

Create Default Path When Terminal Is opened
 
My terminal goes to /home/$USER when I click on terminal.

However, I am doing BASH scripting and I want the terminal to automatically go to /home/$USER/bash_folder whenever I double click on the terminal.

So how is this done?

markush 08-22-2011 07:32 AM

Hi hitmen,

you can simply add a line to your .bashrc
Code:

cd bash_folder
provided the .bashrc is sourced when you open a terminal. If not, you'll have to find out which file is sourced (it depends on the distribution), read the manpage for bash.

Markus

hitmen 08-22-2011 07:51 AM

This is seriosly a noob question but there are so many bashrc files, so which one am I supposed to edit?

c@c-laptop:~/Desktop$ locate .bashrc
/etc/bash.bashrc
/etc/skel/.bashrc
/home/c/.bashrc
/home/c/.bashrc.swo
/home/c/.bashrc.swp
/root/.bashrc
/usr/share/base-files/dot.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/bash.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/skel/dot.bashrc

markush 08-22-2011 07:58 AM

Well, this is not newbie question because it depends.

here the appropriate text from the bash-manpage
Quote:

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.

When a login shell exits, bash reads and executes commands from the file ~/.bash_logout,
if it exists.

When an interactive shell that is not a login shell is started, bash reads and executes
commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc
option. The --rcfile file option will force bash to read and execute commands from file
instead of ~/.bashrc.
you should check if such a file (.bashrc or .profile and so on) is in your home-directory, if not create one.

When you open a terminal in X, bash isn't invoked as a login-shell, therefore a .bashrc file should be sourced. You'll have to try it out.

Note that it is possible (but I don't know) that you can change the path in the properties of the terminal-button in the menu (or wherever you click). In KDE this is possible, but I suppose you're using Gnome.

Markus

chrism01 08-22-2011 07:23 PM

Normally that'd be the one in your home dir...

MTK358 08-23-2011 06:03 PM

Quote:

Originally Posted by hitmen (Post 4450033)
My terminal goes to /home/$USER when I click on terminal.

It actually goes to $HOME, not /home/$USER. It's possible for a user to have a home directory not named /home/$USER.

Quote:

Originally Posted by hitmen (Post 4450061)
This is seriosly a noob question but there are so many bashrc files, so which one am I supposed to edit?

"~/.bashrc", since it's the only one that's not system-wide.

The "*.swp" and "*.swo" files are files used by the Vim editor. If there's a swap file called ".example.swp", it means that either there is an instance of Vim running that has the file "example" opened in it, or that an instance of Vim that was editing "example" wasn't closed properly.

verzonnen 08-23-2011 07:37 PM

To add this to your bashrc in the terminal enter the following command;
echo "cd /where/ever/you/want/to/go" >> ~/.bashrc

Remember to make a copy of the .bashrc file and to test it after before logging out (you can test by reading the .bashrc back into the current shell by entering ". .bashrc" this time without the quotes)

Good luck.

hitmen 08-26-2011 12:23 AM

Got A few questions.
 
Ok here is the relevant output in my home folder:

c@c-laptop:~$ ls -la
total 60220

drwxr-xr-x 2 c c 4096 2011-08-22 21:05 bash_folder
-rw------- 1 c c 7530 2011-08-22 21:15 .bash_history
-rw-r--r-- 1 c c 220 2011-01-08 00:43 .bash_logout
-rw-r--r-- 1 c c 115 2011-08-22 21:04 .bash_profile
-rw-r--r-- 1 c c 3007 2011-07-12 21:56 .bashrc
-rw-r--r-- 1 c c 12288 2011-07-12 21:18 .bashrc.swo
-rw-r--r-- 1 c c 12288 2011-07-12 21:15 .bashrc.swp

I have already edited .bash_profile but it doesnt work

c@c-laptop:~$ cat ./.bash_profile
alias ll="ls -l"
alias today='date +"%A, %B %-d, %Y"'

# open bash_folder automatically in terminal
cd bash_folder

HOME/$USER/bash_folder doesnt open when I double click on the terminal.

In addition, the alias 'll' and 'today' doesnt work even though the file is edited. Can anyone explain why?

MTK358 08-26-2011 07:41 AM

Quote:

Originally Posted by hitmen (Post 4453728)
Ok here is the relevant output in my home folder:

c@c-laptop:~$ ls -la
total 60220

drwxr-xr-x 2 c c 4096 2011-08-22 21:05 bash_folder
-rw------- 1 c c 7530 2011-08-22 21:15 .bash_history
-rw-r--r-- 1 c c 220 2011-01-08 00:43 .bash_logout
-rw-r--r-- 1 c c 115 2011-08-22 21:04 .bash_profile
-rw-r--r-- 1 c c 3007 2011-07-12 21:56 .bashrc
-rw-r--r-- 1 c c 12288 2011-07-12 21:18 .bashrc.swo
-rw-r--r-- 1 c c 12288 2011-07-12 21:15 .bashrc.swp

I have already edited .bash_profile but it doesnt work

c@c-laptop:~$ cat ./.bash_profile
alias ll="ls -l"
alias today='date +"%A, %B %-d, %Y"'

Did you completely ignore or misread the last two posts? They say that you should put it in .bashrc, NOT in .bash_profile.

bash_profile is executed when you log in, and its purpose is to set up the environment for all the programs and scripts you will be running. bashrc is a script that's run only when you open an interactive terminal, to set up things like your prompt, convenience aliases, etc. that you only want in interactive terminals. You wouldn't want them in scripts since they can change the way the script behaves.

Quote:

HOME/$USER/bash_folder doesnt open when I double click on the terminal.
The terminal is keyboard-only. Either open a GUI file manager and navigate to that directory, or run:

Code:

cd HOME/$USER/bash_folder
to go to it in the terminal.

hitmen 08-30-2011 11:31 PM

Can you elaborate more on this? :


bash_profile is executed when you log in, and its purpose is to set up the environment for all the programs and scripts you will be running.

grail 08-31-2011 02:06 AM

Try re-reading post #4 and having a look at man bash as all the information you are requesting is there.


All times are GMT -5. The time now is 09:13 PM.