LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-12-2007, 07:51 AM   #1
SlowCoder
Senior Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Debian based
Posts: 1,250

Rep: Reputation: 164Reputation: 164
Meaning of certain commands in script?


Suppose the following script.
Code:
cat myfile | \
while read strLine
do
set -- $strLine
echo $strLine
done
I would like to know the function of the highlighted parts?
I would also like to know when to, and when not to, use the $ in relation to script variables?
 
Old 10-12-2007, 09:48 AM   #2
Tischbein
Member
 
Registered: Oct 2006
Distribution: debian
Posts: 124

Rep: Reputation: 15
Code:
cat myfile | \ <---- the backslash is a linebreak, so the cat
                           is piping into the while statement.

while read strLine
do
set -- $strLine  <----- sets the $* variable to the lines one at a time,
                        so $1 is set to the first word in the line,
                        $2 to the second and so on.

echo "________________"
echo '$* == ' $*
echo '$1 == ' $1 '  $2 == ' $2

echo $strLine

done
 
Old 10-12-2007, 11:21 AM   #3
SlowCoder
Senior Member
 
Registered: Oct 2004
Location: Southeast, U.S.A.
Distribution: Debian based
Posts: 1,250

Original Poster
Rep: Reputation: 164Reputation: 164
Excellent explanation! Thank you.

For clarification, I don't actually need to use set -- $strLine in the example I gave, assuming I just want to display the entire string value? So, really the set line is extraneous?

Can you also answer my 2nd question, regarding when to use the $ symbol? From what I can tell, you don't have to use it when setting a value to a variable, but should use it when getting a value from the same variable?
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
meaning of /etc/security/limits.conf commands marceluda Linux - Security 1 05-11-2006 11:01 AM
"^" meaning in perl/shell script? fhleung Programming 8 01-03-2006 07:27 PM
'./file' meaning in python & shell script Chowroc Programming 7 12-30-2005 02:32 AM
How do I script these commands? johnnybhoy67 Linux - General 6 10-21-2005 09:53 AM
Script to repeat commands satimis Programming 8 08-12-2005 04:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:12 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
Open Source Consulting | Domain Registration