LinuxQuestions.org
Social Bookmarking all things Linux and Open Source
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

Tags used in this thread
Popular LQ Tags , , , ,

Reply
 
Thread Tools
Old 01-25-2008, 02:41 AM   #1
Mr. ameya sathe
Member
 
Registered: Jul 2007
Distribution: RedHat Enterprise 5 Server Edition; Ubuntu 8.04 ; RHCE Certificate number: 805008741034103
Posts: 71
Blog Entries: 4
Thanked: 0
Question Contents of Directory Displayed using Arithmetic Expression


[Log in to get rid of this advertisement]
Friday, January 25 2008, 12:58 IST
Dear Friends,
I executed the following command at bash command line.

Code:
echo Area: `expr $X \* $Y`

Output: Contents of the Present Working Directory similar to output of the command '
Code:
ls
' are displayed.

Question: How did this happen?

Yours,
Ameya




Last edited by Mr. ameya sathe; 01-25-2008 at 10:57 AM..
Mr. ameya sathe is offline  
Tag This Post , , , ,
Reply With Quote
Old 01-25-2008, 03:52 AM   #2
Guttorm
Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 597
Thanked: 31
Hi

You forgot to set $X and $Y?

expr \*
Outputs:
*

So:
echo Area: *

Outputs:
"Area: " followed by the content of the current directory.

Remember bash evaluates the * before it executes the echo command.

It's a bit strange but it does make sense.
Guttorm is offline     Reply With Quote
Old 01-25-2008, 11:16 AM   #3
Mr. ameya sathe
Member
 
Registered: Jul 2007
Distribution: RedHat Enterprise 5 Server Edition; Ubuntu 8.04 ; RHCE Certificate number: 805008741034103
Posts: 71
Blog Entries: 4
Thanked: 0

Original Poster
Post

Quote:
Originally Posted by Guttorm View Post
Hi

You forgot to set $X and $Y?

Yes; I have deliberately not set the value of $X & $Y. Their values are undefined.

Quote:
Originally Posted by Guttorm View Post
expr \*
Outputs:
*

So:
echo Area: *

Outputs:
"Area: " followed by the content of the current directory.
.
Thank you for explaining the derivation.
A new question has arisen in my mind; how come the execution of these commands
Code:
$echo *
$echo **
give the listing of the directory contents.

Yours,
Ameya
Mr. ameya sathe is offline     Reply With Quote
Old 01-26-2008, 12:04 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,434
Thanked: 24
I think you need to read up on how shell-globbing works.
osor is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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
Ubuntu Samba "The folder contents could not be displayed" frado Linux - Newbie 2 08-16-2007 06:29 PM
No directory paths displayed at prompt HEMMLine Linux From Scratch 1 03-28-2007 05:03 PM
list contents of directory without listing contents baddah Linux - Newbie 2 06-12-2006 05:02 AM
CD ROM ERROR "folder contents cant be displayed" crunchyuncle Linux - Hardware 3 03-15-2006 10:43 PM
Folder contents canot be displayed - Samba, XP and FC3 gvimalku Linux - Software 3 05-26-2005 12:49 PM


All times are GMT -5. The time now is 01:35 AM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration