Thursday, June 3

How does the following code snippet work?

if grep root /etc/passwd ;then
echo "1"
else
echo "0"
fi

A. The grep command prints 1 on the screen if root is found in /etc/passwd and 0 if it is not.
B. The grep command prints 0 on the screen if root is found in /etc/passwd and 1 if it is not.
C. The grep command searches the /etc/passwd file for the word "root". If it exists grep returns 1 to the if conditional and "1" will be displayed to the screen. If it is not found then grep returns a 0 to the if conditional and "0" is displayed.
D. The grep command searches the /etc/passwd file for the word "root". If it exists grep returns 0 to the if conditional and "1" will be displayed to the screen. If it is not found then grep returns a non-zero value to the if conditional and "0" is displayed.


No comments:

Post a Comment