For anyone in the area of Raleigh, North Carolina this week I will be presenting at the North Carolina Oracle User Group’s fall meeting. I will be giving a presentation on Oracle Shell Scripting which includes several tips and scripts from my book by the same title.
In Firefox (at least version 126.96.36.199 on the PC, I haven’t confirmed this on others) you can search for text by simply typing a slash (/). As long as you’re not in a text entry box the / character will open up the find dialog box just like control-f would.
For those of you who don’t understand the significance of this, in the popular UNIX command line text editor vi you search for text by typing
/string to find. This is typical of how vi works: powerful, simple commands which are rarely obvious.
UNIX and Linux shells provide an abundance of useful built-in information that can be referenced in globally available variables. In order to see the information provided in a shell, the
set command can be run as demonstrated below.
Here’s a partial output of the
BASH_VERSINFO=(="2" ="05b" ="0" ="1" ="release" ="i386-redhat-linux-gnu")
PS1='[\u@\h \W]\$ '
SSH_CLIENT='188.8.131.52 1379 22'
SSH_CONNECTION='184.108.40.206 1379 192.168.15.105 22'
The contents of a shell variable can be displayed by using the
echo command and prefacing the variable name with a dollar sign as demonstrated below. Shell variables are referenced using all capital letters.
$ echo $TERM
$ echo $USER
$ echo $HOSTNAME ... $LOGNAME
appsvr.mytec.com ... tclark
There are also some special built-in variables that can be useful when creating shell scripts. Some of them are listed in the table below.
|$#||The total number of arguments passed to a shell script on the command line.|
|$*||All arguments passed to the shell script.|
|$0||The command (script) invoked on the command line.|
|$1 – $9||The first through ninth arguments passed to the shell script from the command line.|
These variables are provided by the shell and the names should not be used for other variables.
Aliases can be used to perform complex commands but are set in the shell like environmental variables.
If you find yourself frequently using a fairly complicated command like the one below and want to be able to run it without typing the whole thing you can use the
alias command to set up a shortcut.
$ alias alert=â€™tail -200 /u01/installed/software/mypgm/alert.log|moreâ€™
Now you can execute this whole command simply by typing
alert. Many of the features of shell scripting are available in aliases including the pipe (|) used to send the output of one command to the input of another.
If you would like to have an alias automatically set up every time you enter a shell you can add the alias definition to your
.profile file (or whatever file your default shell executes at login.)
A small set of well written aliases can save you a lot of keystrokes, just be careful not to make aliases with the same name as commands you use unless you want the alias to replace that command when you type it.
If a user encounters a binary file and does not know what it is used for or where it came from, they may gain some insight into its origins and use by searching for character strings within the file. If the cat command is used to view a binary file, the user will get a screen full of garbage that will more often than not change the display characteristics. Instead, the
strings command should be used, as demonstrated in the following examples:
Find All Strings in the Binary File
$ strings echo
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%s (%s) %s
Written by %s.
Again the above output has been abbreviated to save space, but you can see that there is some useful information here. Just knowing that “This is free software” and that it is copyrighted by the Free Software Foundation can give you some great insight on where this came from and why it might be there.
Finding Occurrences of a String in a Binary File
Here we show how the output of the
strings command can be piped into the
grep command to look for specific words within a binary file.
$ strings echo|grep GLIBC
This shows how
grep can be used to limit the output of a command to only lines that contain certain text.