What does shell check

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions What does shell check
# 1  
Old 12-05-2010
What does shell check

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
When you type a command, the shell checks several places to see if it can find a command with that name to run. Put the following in the order that the shell checks by default.If the shell does not check it by default, remove it

___ All directories in $path
___ All directories in $PATH
___ Hash table created from $path
___ Current directory
___ Built in commands
___ History list
___ System root directory
___ Alias list
___ Shell variables
___ Your home directory


2. Relevant commands, code, scripts, algorithms:
none


3. The attempts at a solution (include all code and scripts):
no idea


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

CharterCollege/Wa/USA/Bryan, Finch/ cs230

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
# 2  
Old 12-05-2010
Do you have a textbook? Almost all of the books I taught out of years ago went in to this explicitly.

What the question is asking: how does a POSIX shell locate a command.

This location "engine" is what the "which" unix command uses. It tells you what type of command : builtin (do you know what that means?), alias (again do you know?), and file (like /usr/bin/ping).

So you need to know what those terms are. Finally look up the PATH variable - it handles the last item in the list: locating command files like /usr/bin/ping. Almost all of the answer is in the reponse, I gave. You need to read a bit and put the pieces together.

If you are going to use UNIX for anything useful, my simply giving you the answer for this would be terrible for you. The above concept is REALLY important, and is the cause of lots of confusion for people who do not know.

If you don't have a text book, I can refer you to some internet pages.
# 3  
Old 12-05-2010
I don't have a text book thats the problem. It was optional for the class and cost 200$ he just gave us a typed document he put together with no real explanation of this process.
Some links would be great!

Last edited by Blockshelf; 12-05-2010 at 06:03 PM..
# 4  
Old 12-05-2010
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:
Code:
alias cmd='some godawful long command that I cannot type well or quickly'

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.
Code:
alias

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.
Code:
PATH="/usr/bin:/usr/local/bin:."

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.

Code:
echo "$PATH"

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
Code:
foo="ls -l myfile.dat"
# simply type
$cmd

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]
# 5  
Old 12-05-2010
Thank you very much that makes more sense then what I have explained through the paper provided. I have went over it and have my answer. My next hurdle is bc calculating a small float calculation. I haven't used bc and I am not sure how to code it. I am familiar with some other coding but don't know where to start on this one. A link to something or another great explanation would be awesome.

I need to create a script that converts pounds to kilos. I need to record the input from the user for pounds calculate it post the conversion and prompt again for pounds. He wants me to use kilos=pounds/2.2
# 6  
Old 12-06-2010
Try this it, covers bc well and in simple terms.

command-line calculations using bc - Basically Tech
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can somebody help me check over my shell scripts??

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)
Discussion started by: Wpgn
5 Replies

2. UNIX for Dummies Questions & Answers

How to check arguments in shell???

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)
Discussion started by: Manueldo
12 Replies

3. Solaris

How to check if a shell is already running ?

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)
Discussion started by: zionassedo
4 Replies

4. Shell Programming and Scripting

help on shell script to check line

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)
Discussion started by: usyseng
3 Replies

5. Shell Programming and Scripting

Help with shell script to check the condition.

:) 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)
Discussion started by: sakthilinux
12 Replies

6. Shell Programming and Scripting

IP check with shell script

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)
Discussion started by: bladez
5 Replies

7. Shell Programming and Scripting

New to Shell scripting: Can you check it?

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)
Discussion started by: sapient
11 Replies

8. Shell Programming and Scripting

Check any MQ is up or down using shell programming

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)
Discussion started by: rinku
1 Replies

9. Shell Programming and Scripting

check my first shell script

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)
Discussion started by: gridview
2 Replies

10. Shell Programming and Scripting

Check length of Shell Variable

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)
Discussion started by: frustrated1
4 Replies
Login or Register to Ask a Question