I am writing a script where I store a predetermined line of text into a string (we will call abc). I am storing the results from grep -iqs $USER file (we will call def) into another string.
How can I test if $abc matches content in $def and if it does, move onto next function....if it does not, prompt user for input?
This is my attempt thus far:
firstFunction() {
abc="$USER content"; #text stored as string
def=`grep -iqs $USER /file`; #results of grep stored to string
if [[ $def = "$abc" ]]; then #test if result from grep command matches text in
secondFunction #string $def. If true, move to secondFunction. If
else #false, prompt user.
echo "Message to user with a y/n prompt"; read prmt;
fi;
if [[ $prmt != "y" || $prmt != "n" ]]; then prmt
elif [[ $prmt == "y" ]]; then
sed -i "s/$def/$abc/g" /file #If user chooses y at prompt, replace $abc with $def
elif [[ $answer == "n" ]]; then #in file. If user chooses no at prompt, move to
secondFunction #secondFunction.
fi;
clear;
};
Environment titles have been changed but the concept behind the snippet should be clear.
case....esac– Kevin Wyman Feb 26 at 6:08