.sh script: check if file exist 1

.sh script: check if file exist

if [ -e x.txt ]
    echo "ok"
    echo "nok"

Here is what the above code is Doing:
1. The first line is a shebang. It tells the shell what program to use to interpret the script.
2. The second line is an if statement. It checks if the file x.txt exists.
3. If the file exists, the script prints ok.
4. If the file doesn’t exist, the script prints nok.

Similar Posts