Openunix.eu
Test [ ] in BASH
- Test if file exists - with an optional if condition example
test -f /var/myapp/log
if [ $? = 1 ]
then echo "No file there!"
else echo "The log file is there"
fi
- Directory exists.
test -d /var/myapp/log
- File exists and is executable.
test -x /var/myapp/log
- Mathematical testing
(( $x >= 15 ))
(( $x >15 )) or [ $x -gt 15 ]
(( $x < 15 )) or [ $x -lt 15 ]
(( $x = 15 )) or [ $x -eq 15 ]
- Checking for empty ENTER input
read -p "Zadej IP adresu BRANY (gateway): " IP_GW
if [ -z "$IP_GW" ] ; then
echo "ENTER PRESSED"
else
echo "SOME OTHER INPUT"
fi
Powered by NetBSD. Running on a toaster.