LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 01-25-2008, 01:41 AM   #1
Mr. ameya sathe
Member
 
Registered: Jul 2007
Distribution: RedHat Enterprise 5 Server Edition; Ubuntu 8.04 ; RHCE Certificate number: 805008741034103
Posts: 78
Blog Entries: 7

Rep: Reputation: Disabled
Question Contents of Directory Displayed using Arithmetic Expression


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 09:57 AM.
 
Old 01-25-2008, 02:52 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,148

Rep: Reputation: 236Reputation: 236Reputation: 236
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.
 
Old 01-25-2008, 10:16 AM   #3
Mr. ameya sathe
Member
 
Registered: Jul 2007
Distribution: RedHat Enterprise 5 Server Edition; Ubuntu 8.04 ; RHCE Certificate number: 805008741034103
Posts: 78
Blog Entries: 7

Original Poster
Rep: Reputation: Disabled
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
 
Old 01-26-2008, 11:04 AM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
I think you need to read up on how shell-globbing works.
 
  


Reply

Tags
bash, command, expression, line


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


All times are GMT -5. The time now is 08:46 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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration