Tag: korn shell

  • Korn Shell Operators

    I write $SHELL scripts most days mostly Korn Shell, I am always looking these two tables up on other sites for the Korn shell rather than commit them to memory, so why not just post it here so I know where to find it forevermore. We mostly use ksh over bash as Korn shell is on every system regardless of the age of that host.

    Korn Shell Operators

    ItemDescription
    -a FileTrue, if the specified file is a symbolic link that points to another file that does exist.
    -b FileTrue, if the specified file exists and is a block special file.
    -c FileTrue, if the specified file exists and is a character special file.
    -d FileTrue, if the specified file exists and is a directory.
    -e FileTrue, if the specified file exists.
    -f FileTrue, if the specified file exists and is an ordinary file.
    -g FileTrue, if the specified file exists and its setgid bit is set.
    -h FileTrue, if the specified file exists and is a symbolic link.
    -k FileTrue, if the specified file exists and its sticky bit is set.
    -n StringTrue, if the length of the specified string is nonzero.
    -o OptionTrue, if the specified option is on.
    -p FileTrue, if the specified file exists and is a FIFO special file or a pipe.
    -r FileTrue, if the specified file exists and is readable by the current process.
    -s FileTrue, if the specified file exists and has a size greater than 0.
    -t FileDescriptorTrue, if specified file descriptor number is open and associated with a terminal device.
    -u FileTrue, if the specified file exists and its setuid bit is set.
    -w FileTrue, if the specified file exists and the write bit is on. However, the file will not be writable on a read-only file system even if this test indicates true.
    -x FileTrue, if the specified file exists and the execute flag is on. If the specified file exists and is a directory, then the current process has permission to search in the directory.
    -z StringTrue, if length of the specified string is 0.
    -L FileTrue, if the specified file exists and is a symbolic link.
    -O FileTrue, if the specified file exists and is owned by the effective user ID of this process.
    -G FileTrue, if the specified file exists and its group matches the effective group ID of this process.
    -S FileTrue, if the specified file exists and is a socket.
    File1 -nt File2True, if File1 exists and is newer than File2.
    File1 -ot File2True, if File1 exists and is older than File2.
    File1 -ef File2True, if File1 and File2 exist and refer to the same file.
    String1 = String2True, if String1 is equal to String2.
    String1 != String2True, if String1 is not equal to String2.
    String = PatternTrue, if the specified string matches the specified pattern.
    String != PatternTrue, if the specified string does not match the specified pattern.
    String1 < String2True, if String1 comes before String2 based on the ASCII value of their characters.
    String1 > String2True, if String1 comes after String2 based on the ASCII value of their characters.
    Expression1 -eq Expression2True, if Expression1 is equal to Expression2.
    Expression1 -ne Expression2True, if Expression1 is not equal to Expression2.
    Expression1 -lt Expression2True, if Expression1 is less than Expression2.
    Expression1 -gt Expression2True, if Expression1 is greater than Expression2.
    Expression1 -le Expression2
    True, if Expression1 is less than or equal to Expression2.
    Expression1 -ge Expression2True, if Expression1 is greater than or equal to Expression2.
    Korn Shell

    You can combine expressions together like below;

    ItemDescription
    (Expression)
    True, if the specified expression is true. Used to group expressions.
    ! ExpressionTrue, if the specified expression is false.
    Expression1 && Expression2True, if Expression1 and Expression2 are both true.
    Expression1 || Expression2True, if either Expression1 or Expression2 is true.
    Korn Shell

    If you enjoyed this on post Korn Shell operators please see some of my others here.