LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 10-10-2011, 08:51 PM   #1
davejjj
LQ Newbie
 
Registered: Oct 2011
Posts: 19

Rep: Reputation: Disabled
Question Bash expanding wildcards?


Somewhere on this site I read a posting that basically explained why I was having newbie trouble with wildcards. It explained that the Bash shell would expand wildcards and then hand them to the command being called. So if I type the command ls a* the ls command would actually receive a line with all the filenames expanded -- and this was giving me the unexpected results, since I then saw the contents of those directories.

ANYWAY -- my question now is: Why does Bash do that? Why would I want that? Do all Linux shells do that? Can I turn that 'feature' off?

Thanks!!!
 
Old 10-10-2011, 09:00 PM   #2
Jenni
Member
 
Registered: Oct 2011
Distribution: Slackware, Fedora
Posts: 158

Rep: Reputation: Disabled
I'm not sure I understand what your question is, for the example command,
Code:
ls Directory/
lists the contents of the Directory,
Code:
ls a*
Lists the contents of all directories that match the criteria set by a*, and all the files in the current directory that meet the criteria.

if you want to list all the directories and files meeting criteria a*, but not the contents of the directories use
Code:
 ls -d a*
the -d flag makes it list directories without listing their contents
 
Old 10-10-2011, 09:10 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Quote:
Why does Bash do that?
Efficiency ... not all commands have the ability to process globs
Quote:
Can I turn that 'feature' off?
Have a look at the shopt command.
 
Old 10-10-2011, 09:19 PM   #4
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
1. because not all progs/utils etc are have built-in wildcard expansion code
2. saves you writing your own wildcard expansion code (see 1.). Its harder than you think, it's effectively a regex engine...
3. yes
4. google shellopt and bash globbing

http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

HTH

Welcome to LQ
 
Old 11-05-2011, 08:00 PM   #5
davejjj
LQ Newbie
 
Registered: Oct 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
The solution I like best for listing directories only is;

ls -l | grep '^d'
 
  


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
Wildcards randalleg Linux From Scratch 3 06-19-2011 09:09 AM
[Bash] How to expand path variable that contains spaces and wildcards jkv Programming 11 02-17-2010 01:19 AM
[SOLVED] trouble expanding 4+TB GPT partition after expanding hardware RAID-5 volume muad'dib Linux - Enterprise 6 09-26-2009 06:01 PM
using wildcards nadroj Linux - General 5 01-28-2007 09:39 PM
auto-completion in bash with wildcards juanbobo Linux - Software 2 04-07-2005 01:56 AM


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