Using a shell to determine whether a device node exists, such as inserting a 4G Modem Sierra module into a Linux system, generates a series of TTY devices, typically with a command to send and receive at. For example, a device node is a/DEV/TTYUSB2 character device.
The judgment script is as follows:
WAIT_FOR_TTYUSB2 () {
While True
Todo
echo "dev= $TTY 2"
If [-C "$TTY 2"]; Then
echo "$TTY 2 is exist"
Break
Fi
echo "Wait for $TTY 2 ready, and check again after 1s"
Sleep 1s
Done
}
The following is a list of judgment conditions that correspond to the type of file or device type.
*-B FILE = True If the file exists and is block special file. If the file exists and is a block special file.
*-c File = True If the file exists and is character special file. If it exists and is a character special file
*-D file = True If the file exists and is directory. If the file exists and is a directory.
*-E File = True If the file exists. If the file exists
*-F file = True If the file exists and is a regular files if it exists and is a normal file
*-G File = True If the file exists and the Set-group-id bit is set. If the file exists and a group ID bit is set.
*-K File = True if the files ' sticky ' bit is set. If the sticky "sticky" bits of the file are set.
*-L FILE = True If the file exists and is a symbolic link. The file exists and is a symbolic link.
*-P file = True If the file exists and is a named pipe. The file exists and is a named pipe.
*-R file = True If the file exists and is readable. The file exists and is readable
*-S File = True If the file exists and its size is greater than zero. File exists, its size is greater than 0
*-S File = True If the file exists and is a socket. File exists and is a socket
*-t FD = True If the file descriptor is opened on a terminal. The file descriptor is opened on a terminal
*-U File = True If the file exists and its Set-user-id bit is set. File exists, its set user ID bit is set
*-W File = True If the file exists and is writable. File exists and can be written
*-X File = True If the file exists and is executable. The file exists and is executable
*-o file = True If the file exists and is owned by the effective user ID. File exists and is a valid user ID
*-G File = True If the file exists and is owned by the effective group ID. The file exists and has a valid GRUOP ID.
Referring to the instructions above, we have to judge that a file exists regardless of its type, so you can use-e, and if you want to check its type at the same time, then we can use the corresponding judgment criteria.