LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-10-2006, 03:48 PM   #1
linuxnoob2006
LQ Newbie
 
Registered: Dec 2006
Posts: 1

Rep: Reputation: 0
Linux Script Help


Hello all,

I very rarely use message boards, but I recently enrolled in a Unix/Linux class and we have to write our own script files. I cannot figure out how to insert a "while" loop in my current script file. I want the loop to revert back to the selection menu after the user makes a selection (ie. They choose #1, the date displays, and then it takes them back to the menu 1-6) Also, what would be a good use of a "here" document and "if" statement within this script file. I am very new to all this and ANY help would be much appreciated. I have read over many script help forums/web pages/text books...but nothing seems to make it clear enough for me to understand how to implement it into an actual script file. I know this script may seem pretty basic, but that's all it has to be, nothing complex. This is the basic layout of the script I am creating, but if you have any other suggestions or neat tricks, I'll give it a try. I am on a tight schedule, with this being due Tuesday 12/12. Thanks in advance...


#!/bin/ksh

cat <<tab
Please enter your selection:


1)Date
2)Users
3)View Files
4)View Directories
5)Current Processes
6)Exit

tab
read ans
echo "You have selected: $ans"
echo "Press enter to continue"
read hold

case $ans in
1)echo "Today's date is:"
echo
date
;;
2)echo "These users are currently logged on:"
echo
who | sort -r | awk '{print $1}'
;;
3)echo "These are my files:"
echo
ls -F | grep -v / | column
;;
4)echo "These are my directories:"
echo
ls -F | grep / | column
;;
5)echo "These are my current processes:"
echo
ps
;;
6)exit 0

esac
sleep 5
clear
 
Old 12-10-2006, 03:56 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
well LQ isn't the place to do your homework for you, but here's a simple example of a while loop:

Code:
i=10
while [ $i -gt 0 ]
do 
  echo $i
  i=$((i - 1))
done
produces:
Code:
10
9
8
7
6
5
4
3
2
1
now you just need to replace the contents i've got in there with whatever you wish to do repeatedly. if you wish to do it forever, remember that the equation in [ ]'s needs to evaulate to true each time. if you never change it, then it's always true.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
same awk script running on linux 7.2 and linux 10 suchi_s Programming 2 11-22-2004 08:47 AM
script in linux spivkid Programming 1 07-27-2004 02:15 PM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 11:22 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 05:21 PM
Exp. Windows/Linux-Script Programmer - Need Linux Programming Mentor! ruttiger Linux - Newbie 2 10-28-2001 12:00 PM


All times are GMT -5. The time now is 05:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration