Passing String as Arguments

#!/bin/bash

function color(){
case $1 in
green) echo -e "\e[1;32m$2 \e[0m";;
red) echo -e "\e[1;31m$2 \e[0m" ;;
*) echo “Color green or red are only allowed
   exit 1;;
esac
}

function checkServiceStatus(){
service_status=$(systemctl is-active $1)

if [ $service_status = “active” ]
then
color green “$1 service has started successfully”
else
color red ”$1 service has failed to start”
fi
}

This is part of my script, it contains function like

color() - To print output in either red or green color
checkServiceStatus() - To check if the service is active or not
If the service is active it will pass arguments to function color to print “service has started successfully” in green or the latter in red

But, when I run the command

checkServiceStatus firewalld

I’m getting the actual output as: "firewalld

Can you suggest what might be made so that I can get the full string as O/P and not just the first word

There’s a couple of issues here

  1. You are using unicode double quotes - “ ” . You must use the normal keyboard one "
  2. Color green or red are only allowed - you are missing a closing quote.

Correct those and it should work
image

Thanks a lot, it worked.