Sponsored Content
Full Discussion: What does shell check
Homework and Emergencies Homework & Coursework Questions What does shell check Post 302477534 by jim mcnamara on Sunday 5th of December 2010 05:20:11 PM
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]
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
All times are GMT -4. The time now is 05:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy