I need a bash script which will find a folder named "Test" in a directory. If it's present there it willn't make the folder named "Test" otherwise it will make a folder named "Test" in the directory. Tried ifs, if, for loop but in vain.
            Asked
            
        
        
            Active
            
        
            Viewed 44 times
        
    0
            
            
        - 
                    4`mkdir -p Test` will create it if it doesn't exist and won't create it if it exists - without complaining. – Ted Lyngmo May 11 '21 at 20:34
- 
                    1See: [How to mkdir only if a directory does not already exist?](https://stackoverflow.com/q/793858/3776858) – Cyrus May 11 '21 at 20:36
- 
                    Does this answer your question? [How to mkdir only if a directory does not already exist?](https://stackoverflow.com/questions/793858/how-to-mkdir-only-if-a-directory-does-not-already-exist) – HoRn May 12 '21 at 08:40
1 Answers
1
            Here's the code you're probably looking for (pretty basic):
folder="Test"
dir="d"
if [[ !(-e $dir/$folder) ]];then 
mkdir $dir/$folder
fi
-e operator, checks if thats anything as name="Test".
 
    
    
        lollobor
        
- 26
- 3
