Shell script with no return function

Asked

Viewed 315 times

2

I have the following function:

function ping {
nome=$(dialog --title "inform o endereço que deseja PINGAR" --inputbox "IP ou URL - \
Lembrando que será disparado 10 pings para o endereço informado." 10 45 --stdout)
status=$?
if [[ $status -eq 0 ]]; then
ping -c 10 $nome
rc=$?
if [[ $rc -eq 0 ]]; then
    echo "#####################################"
    echo "## Endereço: $nome | Status: UP"  
    echo "#####################################"
else
    echo "#####################################"
    echo "## Endereço: $nome | Status: DOWN"
    echo "#####################################"
fi; else; echo "Você optou por cancelar a operação."; fi; } valor=`ping`; echo "RESULTADO FOI: "$valor

But when I run the script (./meuscript.sh), I have no return, only if I select cancel in dialog.

If I run the script without the function, the command is executed correctly, showing me the correct 'Snippets'.

What am I doing wrong? Thank you for your attention!

  • 2

    Place the code instead of placing a code image. It makes it simple to answer your question.

  • 1

    following your suggestion, done.

2 answers

2

The function is very confusing: you have the command at the same time ping of the system and the function ping.

To properly experience the working of the script changes the function name only then you will see the results start to appear:

function pingggg {
nome=$(dialog --title "inform o endereço que deseja PINGAR" --inputbox "IP ou URL - \
Lembrando que será disparado 10 pings para o endereço informado." 10 45 --stdout)
status=$?
if [[ $status -eq 0 ]]; then
  ping -c 10 $nome
  rc=$?
  if [[ $rc -eq 0 ]]; then
    echo "#####################################"
    echo "## Endereço: $nome | Status: UP"  
    echo "#####################################"
  else
    echo "#####################################"
    echo "## Endereço: $nome | Status: DOWN"
    echo "#####################################"
  fi
else
   echo "Você optou por cancelar a operação." 
fi; } 

valor=`pingggg`; echo "RESULTADO FOI: "$valor

2


Browser other questions tagged

You are not signed in. Login or sign up in order to post.