LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 03-07-2006, 02:54 PM   #1
true_atlantis
Member
 
Registered: Oct 2003
Distribution: fedora cor 5 x86_64
Posts: 639

Rep: Reputation: 30
variable question


in the following there is a 0 outputted from 'z=ls | wc -w' and i first thought that z would equal 'ls | wc-w' but was confused about the 0, then i thought that the first command z=ls was being piped to wc -w, but then when echoing z i get nothing. my question is what is happening when 'z=ls | wc -w' is run, and why is there a 0 outputted?




atlantis@linux:~> echo $z

atlantis@linux:~> z=ls | wc -w
0
atlantis@linux:~> echo $z

atlantis@linux:~>
 
Old 03-07-2006, 02:55 PM   #2
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 281Reputation: 281Reputation: 281
Try using back quotes:
Code:
z=`ls | wc -w`
 
Old 03-07-2006, 03:01 PM   #3
true_atlantis
Member
 
Registered: Oct 2003
Distribution: fedora cor 5 x86_64
Posts: 639

Original Poster
Rep: Reputation: 30
yeah, i understand what was wrong. but im just trying to figure out whats going on to output the 0
 
Old 03-07-2006, 03:20 PM   #4
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
the command "z=ls" assigns "ls" to "z" but doesn't output anything, so when you count the words, it's 0
 
Old 03-07-2006, 08:25 PM   #5
true_atlantis
Member
 
Registered: Oct 2003
Distribution: fedora cor 5 x86_64
Posts: 639

Original Poster
Rep: Reputation: 30
if it assigns ls to z then why when echoing $z does it not output ls?
 
Old 03-08-2006, 03:48 AM   #6
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
because this does not assign ls to z:
Code:
z=ls | wc -w
I guess the space breaks up the 'assigning to a variable' since this does not assign anything to z:
Code:
z=word word
whereas these do assign ls to z:
Code:
z=ls
z=ls; wc -w <somefile>
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python variable question bendeco13 Programming 6 02-03-2005 07:22 AM
quick question about PATH variable anders_ant Linux - Newbie 4 11-04-2004 11:17 PM
[c shell] variable question saiz66 Programming 5 09-29-2004 09:45 AM
Enviromental variable question wr3ck3d Linux - Software 3 05-01-2003 06:44 PM
a question about obtaining address of variable ....... purpleburple Programming 3 07-06-2002 05:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:00 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