Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I modify my user PROFILE file to append a scripts folder I created to the end of my PATH variable? [closed]

How do I modify my user PROFILE file to append a scripts folder I created to the end of my PATH variable?

I am not totally sure what this means. Can anyone explain?

like image 818
user1221987 Avatar asked Feb 20 '12 20:02

user1221987


2 Answers

In unix/linux systems, you have a user id ('john') and a home directory ('/home/john'). The home directory has an abbreviation, the tilde: ~ (at the start of a directory path) means the same as your home directory ("/home/john").

In the home directory are several files that begin with a period (aka dot files because they start with a dot, i.e., a period). When you log in, the shell (i.e., the program that processes the command line when you type commands) that is started to supply you a command line looks for these files and reads them, using their content to initialize your shell environment. You can see these files (if they exist) by entering these commands at the command line:

cd
ls -a

The cd with no args means 'change the current directory to be my HOME directory. The ls command lists files in a directory (among other things); the -a option says 'show hidden files'. Hidden files are those that start with a period - this is the convention used in unix/linux to 'hide' files.

The .profile (said out loud it's often pronounced 'dot profile') file is one such dot file used for initializing your environment.

The PATH environment variable is used by the shell to search for executable files (programs).

You can google for 'how to update PATH in profile' and similar to learn more about the topic.

Here is a typical snippet found in a .profile file; its purpose is to allow you to run programs that are stored in the directory /usr/mypackage/bin.

PATH="/usr/mypackage/bin:$PATH"
export PATH

Putting a directory on the PATH allows you to type just a program name ('myprogram') in place of the longer form ('/usr/mypackage/bin/myprogram').

You can see the effect of this snippet using echo $PATH; it will show the entire value of the PATH variable. The value should be a list of paths (directories) separated by colon. A simple example:

echo $PATH
/usr/mypackage/bin:/usr/bin:/bin

That should give you a foothold to begin investigating the details. Trying searching for topics like 'how do I set up my linux/unix login', 'what is .profile file', etc., to learn more.

It's advisable to use double-quotes when setting the value of PATH to encapsulate any 'usual' characters that may be in the names of the items in the path. Single quotes are not suitable for this as they will prevent the evaluation of $PATH (which is what supplies your existing path when defining your new path value). For more on quotes, here is one discussion of single vs double quotes

like image 123
Art Swri Avatar answered Oct 16 '22 08:10

Art Swri


Built-in programs like cat and cd simply work by entering the command. However, they are located in a certain folder, such as /usr/bin/. Try for yourself, and see which folder cat is located in, by entering which cat.

When you type in such command, your shell needs a list of folders in which it has to look for the command just entered. It used the $PATH variable for this, which stores this list. You can see it by entering echo $PATH.

Now, if you close your shell, the $PATH variable is gone. When you reopen your shell, it starts a certain amount of scripts, one of them being the .profile script. In this script, the $PATH variable is loaded. Therefore, you could adjust the .profile file in order to save your $PATH permanently. To do so, simply edit this file and edit the line where $PATH is defined (e.g. pico ~/.profile).

In your particular case, adding your scripts folder to the $PATH like this, will make you can simply write the name of your script instead of the whole pad when you want to launch one.

like image 24
gleerman Avatar answered Oct 16 '22 08:10

gleerman