Bash Scripts if files (plural) exist
So, I've been looking at many forums and I dont find an answer for this. I want to check if some files starting lets say with wx exist or not and use a conditional to check.
For example, having in a folder... wx123.tar wx003.tar wx323.tar wx523.tar df321.tar df542.tar cd123.tar vf213.tar I want to check if there exists files starting with x and move then to another directory in bash scrtipt. So..I tried: . . . if [ -f "wx* ] then ... fi but the * sign doesnt seem to work. Any suggestion or help? Thanks!! |
I suggest you read the man page of find. Particularly the use of the exec option.
|
Code:
shopt -s nullglob |
I removed "PLEASE HELP" from the title---Since you posted the question, we know you want help.
wx* expands to a string including everything in the directory that starts with "wx". That is not what test ([) wants to see. This is why you need a loop. If there is only one file starting with wx, then it works. |
Quote:
|
Quote:
|
Quote:
|
Code:
if ls wx* &> /dev/null |
Quote:
BTW I think the & in &> is superfluous ... ? |
Quote:
If not for the "&", ls would print an error message if wx* does not exist. |
All times are GMT -5. The time now is 07:59 PM. |