Friday, September 11, 2009

Linux - Shell - environment variables basics

The shell is some kind of interface that provides user with the possibility of communication with the Linux system. The most knowable shell is bash.

Environment variables
Environment variables are variables which can make some impact on processes inside of Linux system. Every process in system has a set of associated variables. To get list of environment variables you can use prinenv command:

waldekd@waldekd-laptop:~$ printenv
ORBIT_SOCKETDIR=/tmp/orbit-waldekd
GPG_AGENT_INFO=/tmp/seahorse-8cKqMm/S.gpg-agent:5663:1
SHELL=/bin/bash
TERM=xterm
XDG_SESSION_COOKIE=a49832786c8078ae002e75914a91479b-1252662128.49103-538825691
GTK_RC_FILES=/etc/gtk/gtkrc:/home/waldekd/.gtkrc-1.2-gnome2


Setting environment variable
To set an environment variable use export command:

waldekd@waldekd-laptop:~$ export MYVAR=myvar
waldekd@waldekd-laptop:~$ printenv MYVAR
myvar


waldekd@waldekd-laptop:~$ export PATH=$PATH:/home/waldekd/Desktop/

Aliases

If some of Linux commands (or theirs combination) seem to be more difficult (or hard) to user you can create an alias to them.

waldekd@waldekd-laptop:~$ alias ll='ls -al'

To unset alias unalias command is available:

waldekd@waldekd-laptop:~$ unalias ll

To get list of defined aliases you can use alias command:

waldekd@waldekd-laptop:~$ alias
alias ll='ls -al'

No comments:

Search This Blog