vendredi 13 décembre 2019

How to check existence of multiple files(giving type extension as parameter) in a folder -using bash

Scenario: I have a set of .txt files inside folder and script is checking whether *.txt files exists or not

Script:

set -x
if [ -f  *.txt ]
then
        echo exist
else
        echo not
fi

Output:

+ '[' -f 1.txt 2.txt ']'
test.sh: line 2: [: 1.txt: binary operator expected
+ echo not
not

Aucun commentaire:

Enregistrer un commentaire