Archive for February, 2010

SBDavid

Setting local environment variables

Setting local environment variables

You can set your own environment variables directly from the bash shell.

Once you start a bash shell (or spawn a shell script), you’re allowed to create local variables that are visible within your shell process. You can assign either a numeric or a string value to an
environment variable by assigning the variable to a value using the equal sign:

root@dell:~# process=testing
root@dell:~# echo $process
testing

Now any time you need to reference the value of the test environment variable, just reference it by the name $process.

SBDavid

Local environment variables

Local environment variables

There isn’t a command that displays only local environment variables. The set command displays all of the environment variables set for a specific process. However, this also includes the global environment variables.

Here’s the output from a sample set command.

root@dell:~# set
BASH=/bin/bash
BASH_ARGC=()
BASH_ARGV=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSION=’3.2.39(1)-release’
COLORTERM=Terminal
COLUMNS=99
DESKTOP_SESSION=IceWM

We’ll notice that all of the global environment variables seen from the printenv command appear in the output from the set command. However, there are quite a few additional environment variables that now appear. These are the local environment variables.

SBDavid

Global environment variables

To view the global environment variables, use the printenv command:

root@dell:~# printenv
SSH_AGENT_PID=3334
SHELL=/bin/bash
TERM=xterm
WINDOWID=14680078
USER=root
http_proxy=192.168.1.1:3128
SSH_AUTH_SOCK=/tmp/ssh-ONJxpP3279/agent.3279
MAIL=/var/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DESKTOP_SESSION=IceWM

Global environment variables are visible from the shell session, and any child processes that the shell spawns. Local variables are only available in the shell that creates them. This makes global environment variables useful in applications that spawn child processes that require information from the parent process.

The Linux system sets several global environment variables when you start your bash session (for more details about what variables are started at that time, see the ‘‘Locating System Environment Variables’’ section later in this chapter). The system environment variables always use all capital letters to differentiate them from normal user environment variables.

Most popular archiving tool used in Unix and Linux is the tar command.

The tar command was originally used to write files to a tape device for archiving. However, it can also write the output to a file, which has become a popular way to archive data in Linux.

-c –create create a new archive
-d –diff, –compare find differences between archive and file system
–delete delete from the archive (not for use on mag tapes!)
-r –append append files to the end of an archive
-t –list list the contents of an archive
-u –update only append files that are newer than copy in archive
-x –extract, –get extract files from an archive

tar command is a simple way to create archive files of entire directory structures. This is a common method for distributing source code files for open source applications in the Linux world.

SBDavid

The zip utility

The zip utility

The zip utility there are four utilities in the Linux zip package:

zip creates a compressed file containing listed files and directories.
zipcloak creates an encrypted compress file containing listed files and directories.
zipnote extracts the comments from a zip file.
zipsplit splits a zip file into smaller files of a set size (used for copying large zip files to floppy disks).
unzip extracts files and directories from a compressed zip file.

$ zip
Copyright (c) 1990-2006 Info-ZIP - Type ‘zip “-L”‘ for software license.
Zip 2.32 (June 19th 2006). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]

« Prev - Next »