LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash expanding wildcards? (https://www.linuxquestions.org/questions/linux-newbie-8/bash-expanding-wildcards-907489/)

davejjj 10-10-2011 07:51 PM

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!!!

Jenni 10-10-2011 08:00 PM

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

grail 10-10-2011 08:10 PM

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.

chrism01 10-10-2011 08:19 PM

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 :)

davejjj 11-05-2011 07:00 PM

The solution I like best for listing directories only is;

ls -l | grep '^d'


All times are GMT -5. The time now is 08:30 AM.