Make
if [ "$file" == "*.txt" ]
like this:
if [[ $file == *.txt ]]
That is, double brackets and no quotes.
The right side of ==
is a shell pattern.
If you need a regular expression, use =~
then.
More Related Contents:
- find difference between two text files with one item per line [duplicate]
- How do I tell if a regular file does not exist in Bash?
- How do I parse command line arguments in Bash?
- How do I split a string on a delimiter in Bash?
- Correct Bash and shell script variable capitalization
- How do I compare two string variables in an ‘if’ statement in Bash? [duplicate]
- How can I split a large text file into smaller files with an equal number of lines?
- How to urlencode data for curl command?
- Why equal to operator does not work if it is surrounded by space?
- How to execute a bash command stored as a string with quotes and asterisk [duplicate]
- Execute command on all files in a directory
- Find and Replace Inside a Text File from a Bash Command
- sudo echo “something” >> /etc/privilegedFile doesn’t work [duplicate]
- How to simulate the environment cron executes a script with?
- How can I suppress all output from a command using Bash?
- Remove the last line from a file in Bash
- Random number from a range in a Bash Script
- Recursively rename files using find and sed
- How to get a password from a shell script without echoing
- How do I tell if a file does not exist in Bash?
- Loop through all the files with a specific extension
- How can I set the current working directory to the directory of the script in Bash?
- Deleting lines from one file which are in another file
- Passing arguments by reference
- Get just the filename from a path in a Bash script [duplicate]
- How to use a bash script variable with sed [duplicate]
- Best way to simulate “group by” from bash?
- Determine if a function exists in bash
- Extract version number from a string
- What does `kill -0 $pid` in a shell script do?