Linked Questions

10
votes
3answers
38k views

In a Bash if condition, how to check whether any files matching a simple wildcard expression exist? [duplicate]

Stupidly, I had been using a condition like this as part of a script: if [ $(ls FOO* 2> /dev/null) ] # if files named "FOO*" were downloaded then echo "Files found" # ... process and ...
8
votes
3answers
3k views

How to check if a glob has an expansion? [duplicate]

Is there a good clean conventional way to do this? For example, if there are any ".gz" files in a certain directory, I want to unzip them. But if there aren't, I don't want to see any error. If I ...
2
votes
2answers
20k views

Check if multiple files exist in directory [duplicate]

How to find multiple files present in a directory in ksh (on AIX) I am trying below one: if [ $# -lt 1 ];then echo "Please enter the path" exit fi path=$1 if [ [ ! f $path/cc*.csv ] &&...
0
votes
2answers
10k views

how to check if file exist based on file partial name [duplicate]

the way to check file as all know is like this [[ -f /var/scripts_home/orig_create_DB_files_1.46.38 ]] && echo file exist but how to check if file exist in case file contain name as - "...
1
vote
3answers
2k views

If a file exists in a directory do…? [duplicate]

I am trying to make an if-statement that says: If a file in this directory has .PDF extension do this, otherwise do this... And I'm having a hard time figuring out how to do this in bash. I checked ...
0
votes
2answers
396 views

Bash: Globbing and file conditions [duplicate]

I am trying to check wether a file exists or not: This works as expected: if [ -e "/tmp/test.*.lock" ]; then echo "exists!" fi This does not: if [[ -e /tmp/test.*.lock ]]; then echo "exists!" ...
1
vote
2answers
189 views

Why doesn't my regex work in bash “if”? [duplicate]

Here is my code: if [ -f /Applications/xml[0-9].pl ] I also tried with -f =~ and double brackets but none seem to work. I first though that the regex might be faulty but I tried this. echo h1 | ...
0
votes
2answers
100 views

How to leverage a user defined variable in a command to create a condition in an if [duplicate]

I have a script which takes input for two variables from users. Then, I try to use those variables in a command which is in turn being fed into a condition in an if. However, the user input value is ...
0
votes
1answer
47 views

If/Testing the existence of certain numerous files [duplicate]

In bash, I have a directory that holds some file names that start with underscore _ and others that don't. I want my script to check if a folder has any files that don't start with _. I write if [[ ...
0
votes
4answers
1k views

How can I test for the .RAW file extension?

I'm trying to set up an sh script that will run every 30 minutes. During each run, I want to check a directory for the presence of at least one .RAW file. Upon finding that file extension, I will have ...
0
votes
3answers
118 views

glob variable mandatorily in the double quotes

This link: Wildcards inside quotes in my case not solve the problem. The file "a.sh" contain: file="path with wildcard*" The file "b.sh" contain: . a.sh [ -f "$file&...
-1
votes
1answer
82 views

Why does using double brackets “[[” to check if wildcard matched files exists fail, while single brackets “[” work?

Let's say I generate a two directories with text files in each like so mkdir "Directory1" mkdir "Directory2" touch "Directory1/fileclass1_"{1..5}".txt" touch &...
0
votes
2answers
60 views

Check of folder's content never succeeds

The bash script snippet folder="some folder's name" a="$folder/"*".pdf" if [ "$a" != "$folder"'/*.pdf' ] then echo check fi never prints check. I'd expect it to print check iff there is at ...