Huu Phan | Blog Linux operating system | Linux operating system -Blog Huu Phan | www.huuphan.com
huuphan.com. Powered by Blogger.

Explore the world of seamless email management with Zimbra Mail on Linux! Our blog delves into a step-by-step guide on harnessing the potential of Linux commands, providing easy-to-follow how-tos, and unlocking the magic of Bash scripting. Simplify your email administration journey and enhance your skills with our insightful tips and tricks.

conditional expression bash script

Conditional expression in bash script.For example, check file exists with Conditional expression
Bash script checkfile.sh
 [huupv@huupv scripts]$ cat checkfile.sh 

The content as below:
#!/bin/bash
# author: HuuPV
# for example basic for check file exists!
FILE="/home/huupv/scripts/menu_list"
if [ -f $FILE ]; then
    echo -e "$FILE \t File exists!"
else
    echo -e "$FILE \t File not exists!"
fi
conditional expression bash script


File operators:
-a FILE        True if file exists.
-b FILE        True if file is block special.
-c FILE        True if file is character special.
-d FILE        True if file is a directory.
-e FILE        True if file exists.
-f FILE        True if file exists and is a regular file.
-g FILE        True if file is set-group-id.
-h FILE        True if file is a symbolic link.
-L FILE        True if file is a symbolic link.
-k FILE        True if file has its `sticky' bit set.
-p FILE        True if file is a named pipe.
-r FILE        True if file is readable by you.
-s FILE        True if file exists and is not empty.
-S FILE        True if file is a socket.
-t FD          True if FD is opened on a terminal.
-u FILE        True if the file is set-user-id.
-w FILE        True if the file is writable by you.
-x FILE        True if the file is executable by you.
-O FILE        True if the file is effectively owned by you.
-G FILE        True if the file is effectively owned by your group.
-N FILE        True if the file has been modified since it was last read.
FILE1 -nt FILE2  True if file1 is newer than file2 (according to modification date).
FILE1 -ot FILE2  True if file1 is older than file2.
FILE1 -ef FILE2  True if file1 is a hard link to file2.

String operators:
-z STRING: True if string is empty.
-n STRING: STRING True if string is not empty.
STRING1 = STRING2: True if the strings are equal.
STRING1 != STRING2: True if the strings are not equal.
STRING1 < STRING2: True if STRING1 sorts before STRING2 lexicographically.
STRING1 > STRING2: True if STRING1 sorts after STRING2 lexicographically.

post new :

Huu Phan | Blog Linux operating system | Huu Phan ~ Zimbra Mail Server,linux,bash script,centos,linux command | www.huuphan.com

This Blog is protected by DMCA.com