The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
shell programming nivas Shell Programming and Scripting 8 02-11-2008 08:06 AM
Aix Shell Programming akmtcs AIX 1 12-07-2006 04:40 AM
shell programming Neha Agarwal Shell Programming and Scripting 2 09-06-2005 11:23 PM
Shell Programming Help mec585858 UNIX for Dummies Questions & Answers 4 12-10-2003 06:24 AM
Shell Programming JWK1 UNIX for Dummies Questions & Answers 2 06-01-2001 10:31 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-02-2008
Registered User
 

Join Date: Apr 2008
Posts: 11
need help for shell programming

My purpose was to print out all of name of students in a list.First of all,I created a file name "List" in /home/tuan/Desktop/Shell_programming as below
Code:
Tom
Henry
Ben
Linda
Marry
And my script "script" is
Code:
#!/bin/sh
path=/home/tuan/Desktop/Shell_programming/List
for student in $path
do 
echo "$student"
done
At terminal I did :
Code:
tuan@tuan:~/Desktop/Shell_programming$ chmod +x script
tuan@tuan:~/Desktop/Shell_programming$ /.script
tuan@tuan:~/Desktop/Shell_programming$ ./script
/home/tuan/Desktop/Shell_programming/List
tuan@tuan:~/Desktop/Shell_programming$
Why after executing, the script displayed
Code:
/home/tuan/Desktop/Shell_programming/List
If I would like to print out the name of student. What should I change the code for my script
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-02-2008
Registered User
 

Join Date: Mar 2008
Location: Toronto, Canada
Posts: 66
First try changing yourself with someone who knows unix-shell before writing shell-scripts or at least someone who learns first and then writes code

Then, maybe change "$path" to `cat $path` in the for-statement
Reply With Quote
  #3 (permalink)  
Old 04-02-2008
joeyg's Avatar
premier etoile de match
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 531
Wink suggestion on variable names

I would strongly recommend against using unix keywords as variable names. The word "path" is used for storing locations to find programs for a user. Try typing:
Code:
echo $PATH
to see what I mean.

Yes, uppercase vs. lowercase, but just a matter of there are enough places to make mistakes in unix scripting without causing an extra headache for yourself.

Also, take a look at the following:
Code:
> cat listingnm 
Tom
Henry
Ben
Linda
Marry
Code:
> cat listcontents 
#! /bin/bash

filesrch=listingnm
while read student
   do 
   echo "$student"
done < $filesrch
and the program execution
Code:
> listcontents 
Tom
Henry
Ben
Linda
Marry
Reply With Quote
  #4 (permalink)  
Old 04-02-2008
Registered User
 

Join Date: Apr 2008
Posts: 11
@joeyg:thanks for your advice. It is helpful.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0