LinuxQuestions.org
Register a domain and help support LQ
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 08-14-2013, 09:00 PM   #1
Jeays
LQ Newbie
 
Registered: May 2011
Location: Carleton Place, Ontario, Canada
Distribution: Ubuntu
Posts: 11

Rep: Reputation: Disabled
Strange behaviour of "echo [advance]"


Can anyone explain this behaviour? This is on Mint 13, and it behaves much the same on Ubuntu in a VM, but not in FreeBSD.

Sorry if it is obvious!

europa 521 ~ $ bash --version
GNU bash, version 4.2.8(1)-release (i686-pc-linux-gnu)
...

europa 513 ~ $ echo [adv]
[adv]
europa 514 ~ $ echo [adva]
[adva]
europa 515 ~ $ echo [advan]
[advan]
europa 516 ~ $ echo [advance]
c
europa 518 ~ $ echo [c]
c
europa 519 ~ $ echo [nc]
c
europa 520 ~ $ echo [cn]
c
 
Old 08-15-2013, 12:17 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Unfortunately, I don't a Linux system to hand, but, do you have a file or dir in there called 'c'?

See eg https://www.linuxquestions.org/quest...ax-4175461915/ comments by David_The_H

Last edited by chrism01; 08-15-2013 at 12:25 AM.
 
Old 08-15-2013, 06:06 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
What "[adv]" is doing is attempting a pattern match to identify any file named "a" or "d" or "v".

If nothing matches, then the string "[adv]" is echoed.

As indicated above, it finds a file "c" that matches the pattern, so it displays that file name.
 
1 members found this post helpful.
Old 08-15-2013, 07:33 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by jpollard View Post
What "[adv]" is doing is attempting a pattern match to identify any file named "a" or "d" or "v".

If nothing matches, then the string "[adv]" is echoed.

As indicated above, it finds a file "c" that matches the pattern, so it displays that file name.
To make sure that people don't misunderstand your use of double quotes:

[adv] is attempting a pattern match, "[adv]" works as expected by the OP:
Code:
$ ls -l
total 0
-rw-r----- 1 druuna druuna 0 aug 15 13:30 d

$ echo [adv]
d

$ echo "[adv]"
[adv]
Even better would be:
Code:
echo '[adv]'

Last edited by druuna; 08-15-2013 at 07:35 AM. Reason: Added single quote entry
 
1 members found this post helpful.
Old 08-15-2013, 10:57 PM   #5
Jeays
LQ Newbie
 
Registered: May 2011
Location: Carleton Place, Ontario, Canada
Distribution: Ubuntu
Posts: 11

Original Poster
Rep: Reputation: Disabled
Thanks very much - now I get it.
 
Old 08-16-2013, 03:07 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
You're welcome!

BTW: Can you put up the [SOLVED] tag (upper right corner / Thread Tools menu).
 
  


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
CMake Strange "Install" behaviour with home-grown software [Linux x86_64, CMake 2.8] ajschaeffer Programming 0 10-24-2011 04:21 AM
Strange echo output and "case" error ? budhax Linux - Newbie 3 08-31-2008 10:38 PM
eth0 strange behaviour - reports "disabled" but works with some functions. Keithj Linux - Networking 1 08-29-2008 06:14 PM
BASH: How to NOT echo to screen with "if echo $x | grep ".*"; then" eur0dad Programming 9 07-27-2006 03:14 PM


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