Tuesday, May 16, 2023

if test options and it usage In Linux

if test (expression)

if test !(expression)

if test expression1 -a expression2 

if test expression1 -o expression2

if test -z STRING 

if test STRING1 = STRING2 

if test STRING1 != STRING2

if test INTEGER1 -eq INTEGER2 

if test INTEGER1 -ge INTEGER2 

if test INTEGER1 -gt INTEGER2 

if test INTEGER1 -lt INTEGER2

if test INTEGER1 -le INTEGER2 

if test INTEGER1 -ne INTEGER2 

if test file1 -nt file2                    # -nt :- newer than 

if test file1 -ot file2                    # -ot :- older than

if test -f file                                # if file exists 

if test -d directory_name           # if directory exists 

if test -x file                               # if file is executable 

if test -r  file                               # if file is readable 

if test -w file                               # if file is writable 


if test -s "filename.txt"; then

    # Code to execute if the file is not empty

else

    # Code to execute if the file is empty or does not exist

fi


if ! test -s "filename.txt"; then
    # Code to execute if the file is empty or does not exist
else
    # Code to execute if the file is not empty
fi


if test -n "$myString"; then
    # Code to execute if the string is not empty
else
    # Code to execute if the string is empty
fi


if ! test -n "$myString"; then
    # Code to execute if the string is empty
else
    # Code to execute if the string is not empty
fi



No comments:

Post a Comment

Enable OpenSSH on Windows 11

Step 1: Install OpenSSH Server You can do this via PowerShell (run as Administrator ): Check if it's already available: Get-WindowsCapab...