Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 E-mail Us
 Oracle Articles
New Oracle Articles

 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Oracle Support

 SQL Tuning

 Oracle UNIX
 Oracle Linux
 Remote s
 Remote plans
 Application Server

 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S


 Consulting Staff
 Consulting Prices
 Help Wanted!


 Oracle Posters
 Oracle Books

 Oracle Scripts

Don Burleson Blog 








While Loop

Linux Tips by Burleson Consulting

The while loop executes the commands between the do and done statements while a given condition is true.  The while loop must contain something which will eventually cause the condition to become false, otherwise an infinite loop would occur, and the commands would be executed forever.  The following is an example of the use of a while loop:

$ a=2
$ i=1
$ while [ $i -le 20 ]
> do
>   echo "$a * $i = `expr $i \* $a`"
>   i=`expr $i + 1`
> done

2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18
2 * 10 = 20
2 * 11 = 22
2 * 12 = 24
2 * 13 = 26
2 * 14 = 28
2 * 15 = 30
2 * 16 = 32
2 * 17 = 34
2 * 18 = 36
2 * 19 = 38
2 * 20 = 40

Different loops are useful for different situations.  A poorly written loop can wind up executing indefinitely and may fill your hard drive, use all your processor or cause you to run out of free memory.  Beware of the infinite loop!

The case Statement

Instead of nesting many if-then-else or if-then-elif-then statements, another alternative is to use the case statement.  The case statement allows the user to perform a different set of commands depending upon the value associated with a string variable. 

The following example shows use of the case statement as you might see it in a shell script:

echo -n " What type of pet do you have (dog, cat, etc.)? "
read pet
echo "  "
case $pet in
  dog)    echo " So you have a dog ..."
          echo " That's nice, so do I."
          echo " My dog's name is Fido.";;
  cat)    echo " So you have a cat ..."
          echo " I'm allergic to cats!";;
  fish)   echo " So you have fish ..."
          echo " Can't take them for a walk .. ha, ha.";;
  ferret) echo " Ferrets are cool!";;
  *)      echo " A $pet ... that's a funny pet";;
echo "  "

The case example script above asks the user what kind of pet they have and then provides different responses depending upon the type of pet answered.  It looks for answers of ?dog?, ?cat?, ?fish?, ?ferret?, and ?*?. 

The asterisk (*) matches any other answer supplied by the user.  When a match is found by the case statement, all commands are executed until a double semi-colon (;;) is encountered.

When the example above is entered and saved to a file called, it can be run as shown below:

$ /bin/bash ./

What type of pet do you have (dog, cat, etc.)? moose 
 A moose ... that's a funny pet 

$ ./whatpet.ksh

What type of pet do you have (dog, cat, etc.)? dog 

 So you have a dog ...
 That's nice, so do I.
 My dog's name is Fido.

Now that information has been presented on most of the scripting command constructs, it is possible to begin writing scripts.  The following section lists commands that may be useful in creating scripts.

Linux Command Summary

The following is a fairly comprehensive list of commands available in the Red Hat distribution of Linux.  A brief description of each command is presented in Table 8.7 below.  Some of the commands have been presented in greater detail in previous chapters. 

Rather than spend a great deal of time discussing each command in detail and giving examples of each, the commands are presented here only to give you an idea of what is available.  If you find a command here that might be useful in the development of a script, you can learn more about it with the man or info tools.  Many of the following descriptions come directly from the Linux man pages.

Command   Description


ac prints  out  a  report  of connect time, in hours, based on the logins/logouts in the current wtmp file.  A total is also printed out.


alias with no arguments or with the -p option prints the list of aliases in the form alias name=value on standard output.  When arguments are supplied, an alias is defined for each name whose value is given.  A trailing space in value causes the next word to be checked for alias substitution when the alias is expanded.  For each name in the argument list for which no value is supplied, the name and value of the alias is printed.   alias returns true unless a name is given for which no alias has been defined.


at and batch read commands from standard  input  or  a  specified  file which are to be executed at a later time. at  executes commands at a specified time.  atq lists  the  user?s  pending  jobs, unless the user is the superuser; in that case, everybody?s jobs are listed.   The format of the output lines, one for each job,is: Job number; date;hour; and job class.  atrm deletes jobs identified by their job number.  batch executes commands when system  load  levels  permit;  in  other words,  when  the  load  average  drops below 0.8, or the value specified in the invocation of atrun.


Gawk is the GNU Project?s implementation of the AWK programming language. Gawk - pattern scanning and processing language


Print name with any leading directory components removed.  If specified, also remove a trailing suffix.


bc is a calculator that supports arbitrary precision numbers with interactive execution of statements.


Resume the suspended job jobspec in the background, as if it had been started  with  &.


Exit from within a for, while, until, or select loop regardless of the loop condition.


cal displays a simple calendar.  If arguments are not specified, the current month is displayed.


Cancel jobs


Concatenate files and print on the standard output


chdir changes the current directory to that specified in path.


chfn is used to change finger information.   This information is stored in the /etc/passwd file, and is displayed by the finger program.


Change the group membership files.


Change file access permissions


Change file owner and group


Change the user?s login shell


Checksum and count the bytes in a file


Clears the screen, if possible.


The cmp utility compares two files of any type and writes the results to the standard output.


Filter reverse line feeds from input


Compare two sorted files line by line


compress, uncompress, zcat - compress and expand data


Resume the next iteration of the enclosing for, while, until, or select loop.


Copy files and directories


Copy files to and from archives


Maintain crontab files for individual users


Split a file into sections determined by context lines


Generate tag files for source code


Remove sections from each line of files


Print or set the system date and time


Report filesystem disk space usage


Find differences between two files


Estimate file space usage


Display a line of text


Ed is a line-oriented text editor.  It is used to create, display, modify and manipulate text files.


Grep, egrep, fgrep - print lines matching a pattern


Text editor


Run a program in a modified environment


Cause  the  shell  to exit


Convert tabs in each file to spaces, writing to standard output.


Evaluate and print  the  value of expression to standard output


Exit with a status code indicating failure.


Resume job in the foreground, and make it the  current  job


Grep, egrep, fgrep - print lines matching a pattern


Determine file type


Search for files in a directory hierarchy


User information lookup program


Simple optimal text formatter


Wrap each input line to fit in specified width


Basic file transfer program


Get file access control lists


Grep, egrep, fgrep - print lines matching a pattern


Create a new group


Delete a group


Modify a group


Expand compressed files


Compress files


halt, reboot, poweroff - stop the system


For each name, the full file name of the command  is  determined by searching the directories in $PATH and remembered


Output the first part of files


Display  helpful information about builtin commands


Display recently executed commands


Show or set the system?s host name


Print information for USERNAME, or the current user


Display or configure the kernel-resident network interfaces


Lists the active jobs


Join lines of two files on a common field.  For  each  pair of input lines with identical join fields, write a line to standard output


Terminate a process


Linker.  ld  combines a number of object and archive files, relocates their data and ties up symbol references


Print shared library dependencies


less is a program similar to more , but it allows backward  movement in the file as well as forward movement


Used for pattern matching on text


Make links between files


Security Enhanced version of the GNU locate.  It provides a secure way to index and quickly search  for files on the system


login is used  when  signing  onto  a system.  It can also be used to switch from one user to another at any time


Print the name of the current user


Exit a login shell


Submits files for printing or alters a pending job


Configures printer and class queues provided by CUPS. It can also be used to set the server default printer or class.


Provides limited control over printer and class queues provided by CUPS. It can also be used to query the state of queues.


Shows  the  current print queue status on the named printer


Submits files for printing


Cancels  print  jobs  that  have been queued for printing


Displays status information about the current classes, jobs, and printers


List directory contents


Send and receive mail


The purpose of the make utility is  to  determine  automatically  which pieces of a large program need to be recompiled and issue the commands to recompile them


Formats and displays the on-line manual pages


Controls  the write  access to the user?s terminal by others


Make directories


more is a filter for paging through text one screenful at a time


Mount a file system


Control magnetic tape drive operation


Move or rename files


Format equations for ASCII output


Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships


Log in to a new group


Run a program with modified scheduling priority


Run a command immune to hangups, with output to a non-tty


Query Internet name servers interactively


Update a user?s authentication tokens(s)


Merge lines of files.  It write  lines  consisting  of  the sequentially corresponding lines from each file, separated by tabs, to standard output


Practical Extraction and Report Language
pgrep Looks through the currently running processes and lists the  process  ids which match the selection criteria to stdout


Uses the ICMP protocol?s mandatory ECHO_REQUEST datagram to elicit an  ICMP  ECHO_RESPONSE from a host or gateway


Will send the specified signal, by default SIGTERM, to each process instead of listing them on stdout


Halt, reboot, poweroff - stop the system


Paginate or columnate file(s) for printing


Format and print data to the standard output


Report process status


Print name of current/working directory


Remote file copy ? copies files between machines


Halt, reboot, poweroff - stop the system


ed is a line-oriented text editor.  It is used to create, display, modify and otherwise manipulate text files.  red is a  restricted ed:  it can  only  edit files in the current directory and cannot execute shell commands.


Remote login


Remove files or directories


Handle remote mail received via uucp


Remove empty directories


Report remote procedure call (RPC) information.  It makes a RPC call to a RPC server and reports what it finds.


Remote shell


Psed - A stream editor that reads the input stream consisting of the specified files (or standard input, if none are given), processes it line by line by applying a script consisting of edit commands, and writes resulting lines to standard output.


Collect, report, or save system activity information


Makes a typescript of everything printed on a terminal


Find differences between two files and merge interactively


A stream editor.  A stream editor is used to perform basic text transformations on an input stream


An electronic mail transport agent that sends a message to one or more recipients, routing the message over whatever networks are necessary


Display, set or unset shell attributes.


Change or add an environment variable


Set file access control lists


The bourne shell.  bash is an bourne-compatible command language interpreter that executes commands read from the standard input or from a file.


Brings the system down in a secure way.  All logged-in users are notified that the system is going down, and login is blocked.


Delay for a specified amount of time or pause for number of seconds


Sort lines of text files


Split a file into pieces


Change and print terminal line settings


Change the effective user id and group id to that of another user


Execute a command as another user.  It allows a permitted user to execute a command as the superuser or another user, as specified in the sudoers file


Returns information on overall system statistics


Output the last part of files


The tar archiving utility


Read from standard input and write to standard output and files


The  telnet  command is used to communicate with another host using the TELNET protocol


Time a simple command or give resource usage


Update  the  access  and modification times of each file to the current time


Initialize a terminal or query terminfo database


Translate, squeeze, and/or delete characters from standard input, writing to standard output


Print the route packets take to a network host


The troff processor of the groff text formatting system


Do underlining


Set the user file-creation mask


Remove  a  named alias  from  the list of defined aliases


Print certain system information


Expand compressed data


Remove duplicate lines from a sorted file


Create a new user or update default new user information


Delete a user account and related files


Modify a user account


A powerful text editor.


Start the vi editor in read-only mode


Wait for the specified process and return its termination status.


Print byte, word, and newline counts for each file, and a total line if more than one file is specified.


Locate the binary, source, and manual page files for a command


Shows the full path of shell commands




Show who is logged on


whois searches Whois servers for the named object.


The X Window System is a network transparent window system which runs on a wide range of computing and graphics machines


Display all the characters in an X font


Server font list displayer for X


X server resource database utility


User preference utility for X


The xterm program is a terminal emulator for the X Window System


Compress or expand files

This is an excerpt from "Easy Linux Commands" by Linux guru Jon Emmons.  You can purchase it for only $19.95 (30%-off) at this link.



Oracle Training at Sea
oracle dba poster

Follow us on Twitter 
Oracle performance tuning software 
Oracle Linux poster


Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


Copyright © 1996 -  2017

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

Remote Emergency Support provided by Conversational