Since the contents of variables will, well, vary it is often useful to be able to make decisions based on them. Strings and numbers can be easily compared to explicit values or other variables. Here is a simple example:

$ i=107
$ if [ $i -gt 100 ]
> then
> echo “Wow, i got all the way up to $i”
> else
> echo “i is only up to $i”
> fi
Wow, i got all the way up to 107
$ i=22
$ if [ $i -gt 100 ]
> then
> echo “Wow, i got all the way up to $i”
> else
> echo “i is only up to $i”
> fi
i is only up to 22

Here we see a simple if statement. When executed the expression within the brackets is evaluated to either true or false. If the expression is found to be true the commands after the then will be executed, otherwise the commands after the else are executed.

The expression shown here is the greater than expression (>). The symbols we typically use for greater than and less than have specific significance in the UNIX shell, so to compare values we use -gt for greater than and -lt for less than. Comparisons can also be made between strings of text. More information about comparing text and numbers can be found in my book.

Oracle Shell ScriptingFor more information like this check out my book Oracle Shell Scripting, only $34.95 from Rampant TechPress.

Buy it now!


My book, Oracle Shell Scripting has received another 5-star review on Amazon!

A. Tucker “Rat” writes:

Oracle administrators of all levels will find benefit in this book. The author has put together the basics in shell scripting and OS fundamentals in aid of maintaining and monitoring scalable production Oracle environments. Each example is easy to read and follow and leaves the reader with room to explore and extrapolate on their own with little effort. A great lookup source for old timers and “must have” for newbies.

I highly recommend this book
-Rat

Thanks for the great review Rat!

Oracle Shell ScriptingCheck out my book Oracle Shell Scripting, only $34.95 from Rampant TechPress.

Buy it now!


Well, I’m glad to see that people are liking my book Oracle Shell Scripting: Linux and UNIX Programming for Oracle. Another 5-star review showed up on Amazon last week:

Jolly writes:

Great book!

A well written book. A great way to learn shell scripting. Relevant and useful examples throughout the book (downloadable code).

Thanks for the review Jolly!

Oracle Shell ScriptingFor more information like this check out my book Oracle Shell Scripting, only $34.95 from Rampant TechPress.

Buy it now!


When you connect to a system, whether directly on the system’s keyboard or through a remote connection you will automatically start in your default shell. The default shell was originally assigned to you when your account was created.

To find out what shell you are currently using we can use the echo command:

$ echo $SHELL
/bin/bash

In this command we are using the echo command to examine the value of the environment variable $SHELL. This variable was set by the system when we started this command line session and shows the full path to the shell we were assigned at login. Here are some common shells you might see:

  • /bin/sh – Bourne shell
  • /bin/bash – Bourne Again shell
  • /bin/csh – C shell
  • /bin/ksh – Korn shell
  • /bin/tcsh – TC shell
  • /bin/zsh – Z shell

Shell binaries are also commonly found in the /usr/local/bin directory. Consult your system administrator if you’re having trouble finding your shell binaries.

Oracle Shell ScriptingFor more information like this check out my book Oracle Shell Scripting, only $34.95 from Rampant TechPress.

Buy it now!


Another review for my book Oracle Shell Scripting: Linux and UNIX Programming for Oracle has shown up on Amazon!

Prashant wrote:

This book has helped me impress my colleagues and boss..I originally browsed through it at Border’s (and found myself sitting on the ground with a notepad scrambling to copy as much as possible)..of course, then I realized I had to have it, so I bought it online..I knew the publisher was a trustworthy source because I’m always using Don Burleson’s DBA tips online.. this author’s approach is easy-to-follow and concise; yet it’s a thorough guide that is like a catalyst for your own creativity…it has made me look forward to extracting the power of the shell.

It’s a lot better than parsing through thick UNIX encyclopedias or cycling through fragmented online material..as an OCP 10g/9i DBA, I still feel like there are not enough practical day-to-day guides like this one for junior/mid/senior-level administrators, since over half our work is directly/indirectly connected to the shell.

Thanks for the great review Prashant! After all the work that goes into a book like this it’s great to know that it’s helping people. That’s what it’s all about, after all.

Oracle Shell ScriptingFor more information like this check out my book Oracle Shell Scripting, only $34.95 from Rampant TechPress.

Buy it now!


Next Page »