Judgment file:
Workdir=/home/tmp
local_list_file= $WORKDIR/local.list
#if no Local.txt file, generate a new one
if [!-F "$LOCAL _list_file"]; Then
Touch $LOCAL _list_file
Fi
Note: Be sure to have a space, to determine whether the file exists, if it does not exist, to generate a new
if [!-d/mnt] # Be sure the DIRECTORY/MNT exists
Then
Mkdir/mnt
Fi
Directory. /MNT exists, does not exist on the build directory/mnt
The tests below are test conditions provided by the shell:
*-B FILE = True If the file exists and is block special file.
*-c File = True If the file exists and is character special file.
*-D file = True If the file exists and is directory.
*-E File = True If the file exists.
*-F file = True If the file exists and is a regular file
*-G File = True If the file exists and the Set-group-id bit is set.
*-K File = True if the files ' sticky ' bit is set.
*-L FILE = True If the file exists and is a symbolic link.
*-P file = True If the file exists and is a named pipe.
*-R file = True If the file exists and is readable.
*-S File = True If the file exists and its size is greater than zero.
*-S File = True If the file exists and is a socket.
*-t FD = True If the file descriptor is opened on a terminal.
*-U File = True If the file exists and its Set-user-id bit is set.
*-W File = True If the file exists and is writable.
*-X File = True If the file exists and is executable.
*-o file = True If the file exists and is owned by the effective user ID.
*-G File = True If the file exists and is owned by the effective group ID.
* File1–nt file2 = True If file1 is newer, by modification date, than file2.
* file1 ot file2 = True If file1 is older than file2.
* File1 EF file2 = True if file1 and file2 have the same device and inode numbers.
*-Z string = True If the length of the string is 0.
*-N String = True If the length of the the string is Non-zero.
* string1 = string2 = True If the strings are equal.
* string1!= string2 = True If the strings are not equal.
*!expr = True If the expr evaluates to false.
* Expr1–a EXPR2 = True if both Expr1 and EXPR2 are True.
* Expr1–o EXPR2 = True is either EXPR1 or EXPR2 is True.
Data problems in the shell
Arrayname= ("element 1", Element 2 "element 3") #数组定义
echo ${#ArrayName [@]}
echo "The number of elements in the array is ${#ArrayName [*]}"
Example
#!/bin/bash
# define array
# Name server names FQDN
nameservers= ("Ns1.nixcraft.net." "Ns2.nixcraft.net." "Ns3.nixcraft.net.")
# Get length ' an array
tlen=${#NAMESERVERS [@]}
&nbs P
use for loop read all nameservers
for ((i=0; i<${tlen}; i++));
& nbsp; do
echo ${nameservers[$i]}
done
& nbsp; Sample output:
ns1.nixcraft.net.
Ns2.nixcraft.net.
ns3.nixcraft.net.