if file *.txt then do x else if *.mp3 file then do xx (bash)
So I want to check if there is a file that has an extension of ether .txt or .mp3 and to exicute code if one is found.
Kinda like this: (but this doesn't work for obvious reasons :( ) Code:
for rfile in *.txt *.mp3; do |
You could break it up into two loops.
Code:
for rfile in *.txt; do find . -type f -iname "*.txt" -exec <command> \; find . -type f -iname "*.mp3" -exec <command> \; Be sure to read through the bash info manual. In particular the section on "test" & "[[" and the section on variable expansion. also enter "help test" in the shell. |
Thanks jschiwal!
Really appreciate your help, I will use the 2 for loops for now. When I have some more time ill look into the other options for a more permanent solution. |
Try this. Use the for loop to find the files you want, then test them with an if or case statement. I prefer case myself usually. {} can be used to match multiple patterns at once.
Code:
for rfile in *.{txt,mp3}; do |
All times are GMT -5. The time now is 03:51 AM. |