What's New!

Chat with

How to Defend
Your Computer 

The Guides
to (mostly) 
Harmless Hacking

Happy Hacker 
Digests (old stuff) 

Hacker Links 


Meet the 
Happy Hacksters 

Help for 



It Sucks 
to Be Me!

How to Commit
Computer Crime (not)! 

What Is a 
Hacker, Anyhow? 

Have a 
Great Life! 

News from the 
Hacker War Front

The Bash Shell,continued...

Environment Variables

    If you have any programming experience at all, or you have been reading the Guides like a good little hacker, then you will know about Variables. Think of these as named pieces of your computer's memory which hold values. Depending upon the variables in question, you may or may not have immediate control of their contents.

   Another concept is your environment, which is what you find when you give the "env" command. Much like the real world you live in, your environment in your shell stores information such as the operating system you are running, the version, your home directory, a list of directories to look at when you want to run a program, and so on.

   Some of the more common bash environment variables that you will want to know a bit about are:

      this is a colon-separated list of directories which bash uses to
search for commands. eg:

      the current users home directory, eg:

      a colon-seperated list of directories to search when you issue the
      cd command, eg:
      if you had a directory under /usr/local/etc called myGreatProg,  you could issue a cd myGreatProg on the command line and you would be taken to the first occurrence of myGreatProg in CDPATH. In this case, /usr/local/etc/myGreatProg. When it comes down to it, this is not necessary, it's just a nicety which can confuse you at times. Use with care!

      a colon-separated list of spool files which bash checks periodically for new mail, eg:

   PS1 & PS2
      primary and secondary prompt strings. The primary prompt is used at your standard interactive shell. ie; when you log in or you run bash.

  The secondary prompt is used when bash needs more input to complete a command. for example, at the prompt, type:

            cd \

      bash will change the prompt to ">" or whatever your PS2 is set to, indicating that you need to type more before it can execute your instruction. Try typing:


      and after you press ENTER, the complete command will have been "cd ~".
      This takes you to your home directory. The backslash "\" indicated that the command continues on the next line. This can be used in your scripts as well for long lines that you don't want to get too messy.

      This is a nice variable which you can call upon to give you a random number. Assigning a number to this will allow you to generate a seed. This is a nifty idea, but unfortunately, it is not entirely random. After executing this a few times, I noticed a pattern, so if you are going to use It, take care. Mind you, if you were going to write some really flash crypto routine, then you'd probably be using a programming language as opposed to a
scripting language :)

    To set variables, you can use the set command, eg:

set TEMP_VAR=cheese

    But this will not export it into the environment in bash. to do that, you must use export, eg:

xport TEMP_VAR

    You can, however, just use export, thus:

export TEMP_VAR=cheese

More on the bash shell --->> 

Carolyn's most
popular book,
in 4th edition now!
For advanced
hacker studies,
read Carolyn's
Google Groups
Subscribe to Happy Hacker
Visit this group


Return to the index of Guides to (mostly) Harmless Hacking!

Return to the index of Guides to (mostly) Harmless Hacking!

 © 2013 Happy Hacker All rights reserved.