-1

My code is the following:

vpnname="test vpn"
    
booleanCheck(){
    echo $1
    if (statement) then
       sendMail $1
    }
    
    sendMail(){
    mailsubject = "subject test for - $1" 
}
    
if ! ping 8.8.8.8 then
then 
    checkIfSendEmail "$@$vpnname"
fi

my value of the second last line passes greatly to booleanCheck() but once it gets to sendMail(), the value gets lost. what am i doing wrong?

i tried showing it by "$1" or '$1' or $@$1 o ${1} in the function sendMail() without a result

Kahn Kah
  • 1,389
  • 7
  • 24
  • 49
  • 1
    your code doesn't look tidy, for example what's to do with your double `then` and missing `fi`? And are you expecting `ping` to exit on its own? – iBug May 16 '21 at 00:21
  • they are only snippets to be sure i'm only showing the most important – Kahn Kah May 16 '21 at 00:22

1 Answers1

1

Wrap all your variables in double quotes while passing so any spaces in between won't get split:

booleanCheck(){
    echo "$1"
    if (statement) then
        sendMail "$1"
    fi
}

Recommended: Use shellcheck to eliminate these obvious bad practices.

iBug
  • 35,554
  • 7
  • 89
  • 134