LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-28-2004, 02:47 PM   #1
saiz66
Member
 
Registered: Apr 2003
Posts: 225

Rep: Reputation: 30
[c shell] variable question


If I have a variable such as username = {abc def ghi} Is there a way I could evaluate each of these names separately? For example, I wanted to echo each of the 3 seperate, echo "abc", echo "def" and echo "ghi".. Any ideas?
 
Old 09-28-2004, 02:53 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,814

Rep: Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553
Don't know c-shell, but
Code:
echo $username|cut -d' ' -f1
etc would work in ksh, bash....
 
Old 09-28-2004, 05:16 PM   #3
saiz66
Member
 
Registered: Apr 2003
Posts: 225

Original Poster
Rep: Reputation: 30
thanks chris.. how would I find the end though? for your code:

Code:
echo $username|cut -d' ' -f1
it only shows the first one... I figured that if you put f2 and f3 you will get the other parts.. but how can I get it since I don't know how many number of names there would be in that variable to display them all? Also I found out that you can do

Code:
username[1]
and it would display the first name.. but I dont know how to find the end of the string.. is there a EOF?

Last edited by saiz66; 09-28-2004 at 05:23 PM.
 
Old 09-28-2004, 08:12 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 20,644

Rep: Reputation: 3652Reputation: 3652Reputation: 3652Reputation: 3652Reputation: 3652Reputation: 3652Reputation: 3652Reputation: 3652Reputation: 3652Reputation: 3652Reputation: 3652
Try
Code:
  foreach name ( user1 user2 user3 )
      echo $name
   end
BTW it might be time to invest in a shell programming book
 
Old 09-28-2004, 09:27 PM   #5
saiz66
Member
 
Registered: Apr 2003
Posts: 225

Original Poster
Rep: Reputation: 30
thanks for the reply!!!! and what programming book would you recommend?

Last edited by saiz66; 09-28-2004 at 09:30 PM.
 
Old 09-29-2004, 10:45 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,814

Rep: Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553Reputation: 2553
Try this: http://freeos.com/guides/lsst/
and this: http://www.icon.co.za/~psheer/book/index.html.gz (Linux HOWTO book, inc shell prog)
 
  


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
Shell Script Random Variable Daniel Programming 14 12-03-2007 06:00 AM
How can change value of shell Builten variable LinuxLover Linux - Software 3 08-09-2005 02:12 PM
Export Shell Variable not working maxhugen Linux - Newbie 6 01-06-2005 11:12 PM
shell question variable substitution dpressm Programming 9 11-18-2004 08:00 AM
Expanding shell variable in sed goofyheadedpunk Programming 4 09-11-2004 06:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:24 PM.

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
Open Source Consulting | Domain Registration