Giter Club home page Giter Club logo

bash-path-activity-web-060517's Introduction

Path Activity

What is $PATH?

In your .bash_profile (and Unix in general), a variable is characterized by a dollar sign followed by a variable name. Conventionally, environment variable names consist of all uppercase letters. One example of this is $PATH.

$PATH is a colon-separated list of paths. Each path is just the location of a directory (or "folder") on your system. When you type a command into your command-line, you are running a program. But where does that program live? When your computer receives a command to run a program, it will seach for that program in the directories listed in your $PATH.

Where is $PATH defined?

$PATH can be defined in a few different places on your computer:

For an individual user:

  • ~/.bash_profile
  • ~/.bashrc

For global changes:

  • /etc/profile
  • /etc/bashrc

Activity

Echo $PATH

To gain a better understanding of how $PATH works, type in echo $PATH. Your terminal should print the value of your $PATH variable. Mine looks like this:

/Users/amandachang/.rvm/gems/ruby-2.2.0-preview1/bin:/Users/amandachang/.rvm/gems/ruby-2.2.0-preview1@global/bin:/Users/amandachang/.rvm/rubies/ruby-2.2.0-preview1/bin:/usr/local:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/Users/amandachang/.rvm/bin

On first glance, this looks like an indecipherable string of characters. So let's replace the colons with line breaks. Run the command echo $PATH | tr ":" "\n" to do so. Now I get a list:

/Users/amandachang/.rvm/gems/ruby-2.2.0-preview1/bin
/Users/amandachang/.rvm/gems/ruby-2.2.0-preview1@global/bin
/Users/amandachang/.rvm/rubies/ruby-2.2.0-preview1/bin
/usr/local
/usr/local/bin
/usr/local/sbin
/usr/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/opt/X11/bin
/usr/local/git/bin
/Users/amandachang/.rvm/bin

Imitate your system

So what happens when your computer tries to run Ruby? In order to find the right version, it searches through the directories listed, in order.

Copy the first path in your list, and run ls DIRECTORY_NAME | grep 'ruby'. For example, I will run ls /Users/amandachang/.rvm/gems/ruby-2.2.0-preview1/bin | grep 'ruby'.

Repeat the process with each path in the list until you find Ruby! My ruby was in /Users/amandachang/.rvm/rubies/ruby-2.2.0-preview1/bin. Now run which ruby. The output should match the directory path that you found manually.

Resources

BASH and the One True Path

View Path Activity on Learn.co and start learning to code for free.

bash-path-activity-web-060517's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.