2

I'am creating a shell script, where in I need to pass two parameters (like hash tags) in for loop. for ex. (key value) here I'm comparing "value" parameter with some value and on base of which need to perform some action on "key" parameter.

like:

for i in $(echo `awk '{print $0}' ab4`); or for i in $(cat ab4);
do if [ "`awk -F":" '{print $2}' $i`" = "`some value`" ];
then echo "go ahead and restart app service on `awk '{print $1}' $i`";

{here i'll use the command to restart the service, but for that i need this $1 which is a hostname}

else echo "2nd condition here";
fi;
done.

content of ab4 is like:

hostname app.rpmversion

When i run this, getting error: "key" "value" in ab4 parameters are not a command.

Please assist

1 Answer 1

2

You can use read built-in for this:

while read -r key val; do
   printf "Processing key=%s, value=%s\n" "$key" "$val"
done < ab4

Output:

Processing key=hostname, value=app.rpmversion
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.