| 1 | #!/bin/sh
|
| 2 |
|
| 3 | # When writing scripts and into files, there are times where you have
|
| 4 | # to verify that the file exists, the file is writable, or you need to
|
| 5 | # know if a folder fulfills the same requirements. These commands below
|
| 6 | # can do that
|
| 7 | #
|
| 8 | # -e returns true if the file exists
|
| 9 | # -d true if it's a directory
|
| 10 | # -f true if the file exists and is a regular file
|
| 11 | # -r true if the file is readable
|
| 12 | # -w true if the file is writable
|
| 13 | # -x true if the file is an executable
|
| 14 | # -s true if the file exists and is not empty
|
| 15 | #
|
| 16 | # $ [ -e LICENSE ] && echo 'exists'
|
| 17 | #
|
| 18 | # Find me files that can make the statement true so then echo works.
|
| 19 | # Don't edit the echo messages
|
| 20 |
|
| 21 | touch 22_file
|
| 22 |
|
| 23 | [ ] && echo "Exists"
|
| 24 | [ ] && echo "Directory exists"
|
| 25 | [ ] || echo "empty" # have 22_file be here somehow
|
| 26 | [ ] || echo "Not an executable"
|
| 27 |
|
| 28 | rm 22_file
|