The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
foreach loop ROOZ Shell Programming and Scripting 3 06-05-2008 03:20 PM
foreach loop + 2 variables JamesGoh Shell Programming and Scripting 3 06-04-2008 03:36 AM
foreach loop abch624 Shell Programming and Scripting 1 03-19-2008 09:34 PM
Foreach loop haze21 Shell Programming and Scripting 4 11-16-2007 03:11 AM
foreach loop question clipski UNIX for Dummies Questions & Answers 7 12-22-2005 01:28 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-25-2008
sam4now sam4now is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 23
using foreach loop

hello
any help with this code

cat /etc/passwd/ | cut -d ':' -f5 | foreach user in `who`
then
do
echo `ps -U $user`
done

it does'nt work any way around this
  #2 (permalink)  
Old 04-25-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
who displays who is on the system and field 5 of /etc/passwd are the usernames.
What output are you expected?

Regards
  #3 (permalink)  
Old 04-25-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Quote:
Originally Posted by sam4now View Post
hello
any help with this code

cat /etc/passwd/ | cut -d ':' -f5 | foreach user in `who`
then
do
echo `ps -U $user`
done

it does'nt work any way around this
store the value you get through cat /etc/passwd/ | cut -d ':' -f5
var=`cat /etc/passwd/ | cut -d ':' -f5`
now use your for each loop.
  #4 (permalink)  
Old 04-25-2008
DILEEP410 DILEEP410 is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 148
Question

Hi,

Can anybody please confirm,is there a "foreach" loop in linux schell script ? I found and used one in Perl,but not sure about the Scripting.


Regards
Dileep
  #5 (permalink)  
Old 04-25-2008
Shivdatta Shivdatta is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 73
Refer man foreach.....and check the difference in various shells....
  #6 (permalink)  
Old 04-25-2008
DILEEP410 DILEEP410 is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 148
Post

Quote:
Originally Posted by Shivdatta View Post
Refer man foreach.....and check the difference in various shells....
Thanks for your reply.I got it
  #7 (permalink)  
Old 04-26-2008
sam4now sam4now is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 23
using foreach loop

i am trying to get users who are online,
so am trying to see if foreach loop would get every online users and print each users processes
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0