I am trying to write a Bash script that takes the name of a file or directory as an argument and reports if the file is a directory, regular file or other. The script should also report if the user has read, write and execute permission on the file or directory.
Obviously something like this will get the raw information:
#!/bin/sh read -p "Enter a filename: " fname file $fname ls -la $fname
however, I am wondering if we could just drop the file command completely, pass the filename variable to an ls that we then write some kind of if, then, else statement based on the results. the ls command gives a file type and full break down of the permissions the user running it has on the file, so can I make custom output based on the results of an ls command?
Instead the shell test is recommended. The answer below shows a great example of how to format this.