≡ Menu

echo command

How To Read / Print $PATH Shell Variable

Q. I’m new to Unix / Linux and I’d like to print current values of $PATH variable. How do I read $PATH from a shell prompt?
[click to continue…]

Display or print UNIX / Linux path ~ $PATH variable

Q. How do I print current path settings under BASH shell? I’m using Debian Linux.

A. In UNIX / Linux file systems, the human-readable address of a resource is defined by PATH. On Unix / Linux like operating systems, (as well as on DOS / Windows and its descendants), PATH is an environment variable listing a set of paths to directories where executables may be found.

Display current PATH

Use echo command:
$ echo $PATH


Modify current PATH

Use export command to add /opt/games to PATH, enter:
export PATH=$PATH:/opt/games

To format your PATH variable for easy viewing, add following code to your bash startup file (such as ~/.bashrc or ~/.bash_profile) :

function path(){
    printf "%s\n" $PATH

(Function credit: usenet archive)

Now just run path:
$ path


HowTo Format Date For Display or Use In a Shell Script

How do I format the date to display on the screen on for my shell scripts as per my requirements on Linux or Unix like operating systems?
[click to continue…]

Shell Command / Script To Write Simple Output On Screen Under Linux and UNIX

How do I simply write output from my shell script to the screen under Unix / Linux BASH shell?
[click to continue…]

BASH Shell: Change The Color of My Shell Prompt Under Linux or UNIX

How do I change the color of my shell prompt under Linux or Unix operating systems?
[click to continue…]

sed: Remove All Except Digits (Numbers) From Input

How do I remove all (text, special characters, white spaces, tabs etc) from my text file (input) except numbers (digits) using sed command?
[click to continue…]

How to: Add or display today’s date from a shell script

Q. How can I display or show today’s UNIX computer date from a shell script using echo command? How do I store date command output to a variable?

A. Date command is use to print or set the system date and time under Linux/Unix like operating systems. However some time you need to include today’s date in shell script. You need to use command substitution in your shell script to display today’s date. Bash/sh shell performs the expansion by executing command and replacing the command substitution with the standard output
of the command, with any trailing newlines deleted. Command substitution allows the output of a command to replace the command name. You can use following syntax:

For example, type the following at shell prompt to display today’s date:
$ echo "Today is $(date)"

Today is Sat Jan 28 15:48:11 IST 2006

Here is sample script, that stores today’s date in TODAY and hostname in HOST variable:

echo "-----------------------------------------------------"
echo "Date: $TODAY                     Host:$HOST"
echo "-----------------------------------------------------"
# add rest code...

Save above script and execute it. See working shell script that notify admin user if Linux/FreeBSD system load crossed certain limit