Help with Unix Shell Programming

Posted on 2011-03-20
Last Modified: 2012-05-11
First off, what I need help with is a homework problem and no I am not looking for the answer. I am simply looking for some direction. In 7 weeks we have gone through 13 chapters of UNIX and, being a total N00B to UNIX I am lost. Now we have this project that seems to me impossible given my very limited knowledge of the UNIX OS. What I am looking for is some help structuring the problem into the tasks that I need to do to complete it. For example, "You need to do this first, this second, this third...etc." Please see the attached files.

People tell me I am a geek. Well, I now realize I am not even close. Anyone is any good at UNIX and shell programming has my respect. When this class ends, I don't know if I should start over on the book and go at my own pace or just forget UNIX altogether.  
Question by:BoxunloX
  • 3
LVL 31

Accepted Solution

farzanj earned 500 total points
ID: 35175235
First, take a deep breath and say loud, "Scripting is fun!".

How to Start:
Open a shell script.  I want to give you exercises that would help you understand pieces involved.

Need to Understand:
Shell script is the use of very tiny operations tied together to get a much better functionality.

How to go about it:
Play with little lines of code right on the shell.  If you are good with one liners, you can put them together and get your solution done.

Play with the shell.  Have fun
LVL 31

Expert Comment

ID: 35175347

What do the following commands do?

echo *
Make a directory test
     % mkdir test
     % cd test || echo "cannot change directory"
Now press up arrow key, which should bring the command once again and run the same command again.
Did you notice any difference?
Now issue this command
% cd test || echo "cannot change directory" 2> /dev/null
Did you notice any difference?  If not, use up/down arrow keys and run them over and over again.
This is what I meant by "play and have fun"

Run this command
% for i in *
>  do
>  echo $i
>  done

What did you see
Try this:
% for i in *
>  do
> echo file $i
> done

Now try this:
% myval="good"
% case $myval in
> good) echo "You typed good";;
> bad)  echo "You typed bad";;
> esac

What do you see?

Now do this:
% myval="bad"
Use up arrow to get the above case statement and press enter.
What do you see now?
LVL 31

Assisted Solution

farzanj earned 500 total points
ID: 35175360
I just told you how to play with the shell.  You need to play some more.  So now, you can start playing with your program

Try each command separately and try to understand what each command does.  If you cannot understand anything, you should open separate questions for each part that you don't understand.  This way it will be learning not cheating.

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question