1FILE=/etc/resolv.conf
2if [ -f "$FILE" ]; then
3 echo "$FILE exists."
4else
5 echo "$FILE does not exist."
6fi
7
1# The most readable option when checking whether a file exist or not is
2# to use the test command or the old '[' or the new '[[' in combination
3# with the if statement.
4# Any of the snippets below will check whether the /etc/resolv.conf file
5# exists:
6
7FILE=/etc/resolv.conf
8if test -f "$FILE"; then
9 echo "$FILE exist"
10fi
11
12# or
13
14FILE=/etc/resolv.conf
15if [ -f "$FILE" ]; then
16 echo "$FILE exist"
17fi
18
19# or
20
21FILE=/etc/resolv.conf
22if [[ -f "$FILE" ]]; then
23 echo "$FILE exist"
24fi
25
26
27