Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm following along with linuxcommand.org on the command line and shell scripting. After writing the first script and getting it to run I'm instructed to add: export PATH=$PATH:home_directory to my .bash_profile so I will be able to run the script by typing: my_script rather than specifying the path: ./my_script. But I can't find it. All I have is bash_history, bash_logout, bashrc.
Distribution: Ubuntu based stuff for the most part
Posts: 1,173
Rep:
Go ahead and create the file with the line you want to add. Then either logout and back in, or type "source .bash_profile" to use it in that terminal window.
Okay so I created the .bash_profile and added PATH=$PATH:/home/mikeyd. I then logged out and in again and it wouldn't work. So then I put in the command "$PATH" and recieved this:
bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: No such file or directory
Then after I put in: "source .bash_profile"
it worked, but I have to source it every time I open a terminal. I typed in "$PATH" again and recieved this:
bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/mikeyd: No such file or directory
Just a side note: Only writing $PATH is telling the terminal to execute your path as if it were a command, which doesn't do anything. 'echo $PATH' is the way to have it print out the path.
I don't know about Ubuntu, but there should be a file called /etc/profile, which is a system-wide bash profile. At least in Slackware there's a line at the end specifically for the $PATH of non-root users. Maybe you'd want to use that instead. It's guaranteed to work.
It seems the script works on RPM-based distro such as Fedora,Redhat since the default shell of it is bash.
Can you try to check your current shell via
echo $SHELL
BTW, in debian based, shell is zsh and equivalent is .profile
Another thing I've noticed is when you 'logout', you have to logout completely, not just exit the current xterm.
GUI environments seem to cache your login settings when you first login & apply those to all child xterms.
INVOCATION
A login shell is one whose first character of argument zero is a -, or one started with the --login option.
An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are both connected to
terminals (as determined by isatty(3)), or one started with the -i option. PS1 is set and $- includes i if bash is interactive, allowing a
shell script or a startup file to test this state.
The following paragraphs describe how bash executes its startup files. If any of the files exist but cannot be read, bash reports an error.
Tildes are expanded in file names as described below under Tilde Expansion in the EXPANSION section.
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 /etc/bash.bashrc and ~/.bashrc, if these
files exist. 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 /etc/bash.bashrc and ~/.bashrc.
Ok, so what does that mean for you? A terminal launched inside of X (Gnome, KDE, etc) is not a login shell, so you will have to put your path information into ~/.bashrc or /etc/bash.bashrc, since these are the only rc (run-control) files run when you launch a terminal window.
The same cannot be said if you log in from the console (i.e. if you get out of X using <ctrl><alt><F1>)... this will be a login shell and will use ~/.bash_profile, ~/.bash_login and ~/.profile.
It seems the script works on RPM-based distro such as Fedora,Redhat since the default shell of it is bash.
Can you try to check your current shell via
echo $SHELL
BTW, in debian based, shell is zsh and equivalent is .profile
all debian and debian based distros I used come with bash as default shell.
zsh needs to be installed via apt-get
Add "export PATH" at the end of your .bash_profile or .profile script. This moves a variable to your environment.
The .profile, .bash_login or .bash_profile script will be executed for a login shell. Bash looks for them in that order and executes the first one it finds.
For most distro's if you have a $HOME/bin/ directory, the /etc/profile script or $HOME/.profile script will add it to your PATH variable. Read your /etc/profile script and see if it does that. On my system, a profile script will also check for a $HOME/.bashrc script and source it if it exists. A bin/ directory in your home directory would be a better place for your personal scripts.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.