Function in Shell script with no return

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 the dialog.

If I run the script without the function, the command executes correctly, displaying the correct 'echos'.

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

    
asked by anonymous 13.08.2015 / 05:37

2 answers

2

I asked the same question in the English version and got the following answer!

link

I leave here registered, if someone in the future has the same difficulty as I had!

    
14.08.2015 / 04:24
2

The function is very confusing: you have both the ping system command and the ping function.

To experiment properly, the script changes. name of the function only then you will see the results begin 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
    
08.09.2015 / 16:40