Bash - Check if File or Folder

#!/bin/bash folder=$(pwd) # folder if [ -d "$folder" ]; then echo "This is a Directory: $folder" # or File elif [ -f "$folder" ]; then echo "This is a File: $folder" fi file="./somefile.txt" # folder if [ -d "$file" ]; then echo "This is a Directory: $file" # or File elif [ -f "$file" ]; then echo "This is a File: $file" fi

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.