wildcard in bash shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting wildcard in bash shell script
# 1  
Old 09-07-2010
wildcard in bash shell script

I tried to use the wildcard '*' in my bash script, but I can not get it work. Here is a simple example (list file names in current directory):
ls ./*
does not work in my bash script. But it works if I use
ls ./

So is there any special syntax to use '*' wildcard in bash script (I tested the same thing, but it worked at c shell).

thanks
# 2  
Old 09-07-2010
Quote:
Originally Posted by aerosols
I tried to use the wildcard '*' in my bash script, but I can not get it work. Here is a simple example (list file names in current directory):
ls ./*
does not work in my bash script. But it works if I use
ls ./
There's no special syntax for * in a BASH script. Unless there's too many arguments, it should match like you expect. In what way did it "not work"?

Note that it will print the contents of directories matched, not just the names of directories, as that's what ls does...

"ls *" is redundant anyway, but that's beside the point.

Last edited by Corona688; 09-07-2010 at 10:57 PM..
# 3  
Old 09-08-2010
When I run the script, it gives the following message:
"ls: ./*: No such file or directory"

I can not understand why (I directly type "ls ./*" at command line, it works).

Quote:
Originally Posted by Corona688
There's no special syntax for * in a BASH script. Unless there's too many arguments, it should match like you expect. In what way did it "not work"?

Note that it will print the contents of directories matched, not just the names of directories, as that's what ls does...

"ls *" is redundant anyway, but that's beside the point.
# 4  
Old 09-08-2010
Please post the script.
# 5  
Old 09-08-2010
If you've put them in quotes, asterisks won't expand.
# 6  
Old 09-08-2010
Quote:
Originally Posted by frank_rizzo
Please post the script.
See my script below(I did not quote it at all):

Quote:
#! /bin/bash -f

ls ./*

exit
it gave the error message in my last post. But if replace 'ls ./*' with 'ls ./', it works. thanks a lot!
# 7  
Old 09-08-2010
If the only files in the directory have names starting with "." (like ".profile) they will not match "*".

To see them:

Code:
ls ./.??*

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. Shell Programming and Scripting

Different behavior between bash shell and bash script for cmd

So I'm trying to pass certain json elements as env vars and use them later on in a script. Sample json: JSON='{ "Element1": "file-123456", "Element2": "Name, of, company written in, a very weird way", "Element3": "path/to/some/file.txt", }' (part of the) script: for s... (5 Replies)
Discussion started by: da1
5 Replies

3. Shell Programming and Scripting

Wildcard in bash script

Hi there, I am pretty new to linux scripting so .. I am writing a script to loop through all my directories of sequence files in order to do stuff with them (trimming, normalizing, stuff that one would do with sequence files). Here I need to pick out files that match each other. The files... (10 Replies)
Discussion started by: jahndavik
10 Replies

4. Shell Programming and Scripting

Bash shell script to check if script itself is running

hi guys we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
Discussion started by: hedkandi
8 Replies

5. Shell Programming and Scripting

What does " shell wildcard " shell script?

Hi, I just wondering what does " shell wildcard " Thank (1 Reply)
Discussion started by: guidely
1 Replies

6. Shell Programming and Scripting

help- wildcard not working in shell

hi, i need to check the existence of all files starting with abc in a directory. The code works fine with a particular file name, but the file existence is not detected when i use wildcard character (abc*) kindly suggest what could be the issue :confused: src_filename1=$AI_LANDING/abc*... (11 Replies)
Discussion started by: spirit10
11 Replies

7. Shell Programming and Scripting

Problem when concatinating wildcard onto file location in bash script

I am having difficulty with the following script: #! /bin/bash filelist=~/data/${1}* ~/./convertFile $filelist ~/temp/outputEssentially, there are a large number of files in the directory ~/data, each with a four-letter code at the beginning (eg. aaaa001 aaaa002 bbbb001 bbbb002 etc). The... (11 Replies)
Discussion started by: Lears_Fool
11 Replies

8. UNIX for Dummies Questions & Answers

Bash Wildcard Question

Hi, I am writing a BASH script. In a directory I have a bunch of files of various filename structures. How do I list all the filenames that begin with either a capital or lowercase A or T. Is there one command that could replace the following 4: ls A* ls a* ls T* ls t* Thanks. Mike (3 Replies)
Discussion started by: msb65
3 Replies

9. Shell Programming and Scripting

globbing, $# is too high after wildcard expansion in bash script

How can I pass in an argument such as "*.k" to a bash script without having to double-quote *.k and not having *.k `glob` to match all files in the pattern? I tried using noglob in my script but this didn't work the way I thought it would.. expansion is still occuring, $# is higher than I... (3 Replies)
Discussion started by: zoo591
3 Replies

10. UNIX for Dummies Questions & Answers

Find wildcard .shtml files in wildcard directories and removing them- How's it done?

I'm trying to figure out how to build a small shell script that will find old .shtml files in every /tgp/ directory on the server and delete them if they are older than 10 days... The structure of the paths are like this: /home/domains/www.domain2.com/tgp/ /home/domains/www.domain3.com/tgp/... (1 Reply)
Discussion started by: Neko
1 Replies
Login or Register to Ask a Question