1

I just tried a simple menu based shell script to get the public ip of my system. using ( curl ifconfig.me ) .. but I found it behaving differently.

here I tried with:

anupam@JAZZ:~/Desktop$ cat menuui
#
# Script to create simple menus and take action according to that selection
# menu item
#
while :
do
    clear
    echo "___________________________________"
    echo "Main Menu"
    echo "___________________________________"
    echo "[1] Show Today's date/time"
    echo "[2] Show files in current directory"
    echo "[3] Show calendar"
    echo "[4] Start a calculator"
    echo "[5] Start editor to write letters"
    echo "[6] Show your public ip"
    echo "[7] Exit/Stop"
    echo "===================================="
    echo -n "Enter your menu choice[1-5]:"
    read yourch
    case $yourch in
    1) echo "Today is `date` ,press a key..." ; read ;;
    2) echo "Files in `pwd` "; ls -l;echo "Press a key..."; read;;
    3) cal; echo "Press a key..." ; read ;;
    4) bc;;
        5) vi;;
        6) echo "Your public ip is `curl ifconfig.me`";;
    7) exit 0 ;;
    *) echo "Opps!!! Please select choices 1,2,3,4 or 5";
    echo "Press a key...";read;;
    esac
done

then I executed it... enter image description here

which is not I expected..How could I resolve this??

1 Answer 1

1

Use curl with -s option. From man curl

-s, --silent
          Silent  or  quiet  mode. Don't show progress meter or error mes‐
          sages.  Makes Curl mute. It will still output the data  you  ask
          for, potentially even to the terminal/stdout unless you redirect
          it.

It will not show the additional details such as progress meter or error messages. The modified statement will look like,

echo "Your public ip is $(curl -s ifconfig.me)"

$() is better to use than command substitution quotation ``

2
  • 1
    @jazzz Did it work?
    – sourav c.
    Dec 7, 2014 at 9:22
  • thankx @sourav, but it was taking a lot of time so I switched to use :echo Your public ip is wget http://ipecho.net/plain -O - -q; echo ;read;; and it worked though. :)
    – lazarus
    Dec 8, 2014 at 16:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .