I'm having a problem with my code in bash.
I want my code to check if a file exists on a directory, but since the file will be constantly changing his name, I want to search for his "extension".
So basicly when I start my script, it will check if a directory exists or not, if it doesent it will create it, then I want to check if there is any file starting with a "." (dot) in that directory, if it doesent exist it will create an empty file called ".200"
Here is the code.
#!/bin/bash
directory=$HOME/.impressora
mkdir -p $directory
if [ ! -f "$directory/.*" ]
then echo "" > $directory/.200
the thing is that, after this, I am adding a bunch of code that will keep changing the name of that file, for example, it will go from ".200" , to ".199", to ".198" , to ".197" etc...
So in my "If" statement I have to search if the directory has any file starting with a "." (dot).
I have already used the commands "shopt -s dotglob" and "shopt -u dotglob" to make him ignore the "." and ".." files, puten by default in that directory.
I tried to test this by adding a variable called "file" and try to make it have the value of the extension of the ".200" file and then printing it, but the value that is stored in that variable is ".*" and not "200" has I wanted... Here is the code with the variable.
Directory=$HOME/.impressora
file=$HOME/.impressora/.*
echo "$file"
mkdir -p $directory
if [ ! -f "$directory/.*" ]
then echo "" > $directory/.200
fi
I hope you can help me out, I have been desperately trying to solve this... Thank you.