Well, when you specify a "naked" command like "ls", it means the shell has to figure out what the heck you want. If you issue a command like /usr/bin/ping the command filename is there or it is not there. Simple. No need to figure it out.
Note: ./myscript.sh means execute a file called myscript.sh in the current directory - current directory is what the "pwd" command shows you. This pertains to your assignment so remember it.
The order of lookup is:
1. builtin: builtins are commands like cd, for, while. These are literally part of the shell code itself. They are found first, if they exist.
if #1 fails:
2. alias: alias is a hashed list of commands that are custom-defined by you. Or for you.
For example, suppose you type poorly the way I do - with your elbows. Then a looong
command is cause for frustration due to typos. So:
So, when shell gets the command "cmd" - it goes to the alias table and "recalls" the command for you. alias is also a good way on some OS that have multiple versions of a single command - like awk on Solaris - to specify the one version you want without having to type the full filename of the command all the time.
shows you all of the alias-es you currently have.
if #2 fails:
the shell has to look through a list of directories to see if it can find the command.
This list of directories is stored in the PATH envrionment variable. This is central to answering many of the questions you have to answer.
The colons separate the directories. The shell works from left to right with (based on the example):
/usr/bin
if that fails
/usr/local/bin
if that fails it tries the "dot"
.
. is wierd. It means the directory you are currently in. So it can literally be any directory on the machine. It is bad for privileged users to have that in the PATH variable.
will show you your current PATH. I would assume your prof wants you to use that to answer questions. You could hedge you bets by stipulating EXACTLY what you have in your PATH.
You now have sufficient basic knowledge to answer the questions. Put the pieces together.
There is one weiner in the questions. the 'shell variable'. If you create a shell variable like
The shell first expands the variable, then executes it following all the steps above. If the shell variable is not a valid command it fails. BUT. it requires that you ask the shell to expand it with a $[variable name]
I am using a Korn Shell script..
I need to verify the length of a variable..
ie number=12345
I need then to check 12345 to make sure its no longer than 5 digits...
Can you help? (4 Replies)
I have written the below script to determine whether a string is palindrome or not ?
But its not working, any help to debug it ?
I am new to this forum but when I searched for my question, I found that many people refused to answer this question thinking that its Homework question, Therefore I... (2 Replies)
Hi,
I want to know that if there are any methods, which check the MQ, is up or down. Actually I have to write one job which checks the status of any one MQ is up or down.
I don't know if there is any method of MQ, which tells the MQ, is up.
Could u please give some link for the study... (1 Reply)
I am trying to write a script to get all the html files under a source directory and and for each html file, run a program with html file as an argument. This program generates an output which I need to save as htmlfilename.txt ( right now i was trying to print it on the command line)
... (11 Replies)
hi guys ..newbie here i would like to create a simple script tat will detect wether the machine has IP or not ...
but it seems that my script doesnt really work it kept rebooting...
i set this script during boot so that it will check else it will reboot
it a shell script thou...
... (5 Replies)
:)
Hi,
I want to script for this scenerio,
OSR Settings
Scenario : We are looking to find all the *.a files from the following locations in the filesystem of a server.
OSR Directories
/etc
/bin
/usr/bin
/usr/sbin
/var/adm
These *.a files should have the permissions on... (12 Replies)
Hi Scripting Gurus,
Can someone help to transform the below logic into a shell script, might be easy for some of you.
I have a file with below text, I need if the line has the ":" and the above to it is not a blank line should print " <text>: is incorrect format"
Apple:
... (3 Replies)
Hi,
I put this at start of my shell (korn shell) to be sure that the shell is not already running and sometimes it fails and says that it is already running which is not true !
sleep 1
/usr/bin/ps -ef | /usr/bin/grep "$0" | /usr/bin/egrep -v grep>$LOGDIR/$0.res
isup=$(cat $LOGDIR/$0.res|wc... (4 Replies)
for example I have
make target
file is optional. So can I check whether there is or no? I tried
if test $# -eq 1
then
path=$1
else path=$2
fi
But it doesnt work properlu ;(
Please use code tags next time for your code and data. (12 Replies)
I been having a lot of trouble trying to start up a 3rd party application in Solaris 7 but it seams that its missing entry's when trying to run the files so maybe the start shells scripts have errors and maybe thatr is what is causing the issues I have added two links to the shells can anyone check... (5 Replies)