I have a written a script named phone4 like the following:
# #!/bin/bash name=$1 if ["$name" = ""] then echo -n "Enter a name to search for: " read name fi grep -i $name ~uli101/2017c/phonebook
but now i want to make some change in the script so that if I use the command phone4 xyz if no matching name is found, an appropriate message is displayed: "Name 'xyz' not in directory".
I want to use an 'if' statement to check the value of $? to see if the grep command was successful (remember, '0' indicates success). If the grep is NOT successful, then echo the message (which includes the value of $name).
Make sure this works with both command line arguments and with a name read in from the user, and I need to use the message EXACTLY as "Name 'xyz' not in directory". can anyone help me regarding this?