0

I just started doing some bash script from few days I am not getting any output when running this bash script in terminal please correct me here:

Code:

#!/bin/bash
echo "Usage:"
echo -n "Please enter t/n"
read o
echo -n "IP"
read ip
traceroute () {
  traceroute $ip
}
nmap () {
  nmap -T4 -A -v $ip
}
if [[ "$o" = "t" ]]
then
  traceroute
elif [[ "$o" = "n" ]]
then
  nmap
else
  echo "Usage:"
  echo "Please enter t/n"
  exit 1
fi
4
  • 2
    You are not even getting Usage:? Commented Nov 3, 2016 at 13:58
  • 1
    Could you describe how you are trying to run this script, what are the access rights and what output you get when running the script? Commented Nov 3, 2016 at 14:03
  • 1
    also, I don't think you meant to write /n but rather \n (the correct symbol for newlines) Commented Nov 3, 2016 at 14:04
  • i am running it in root terminal with bash file.bash Commented Nov 3, 2016 at 14:15

2 Answers 2

2

You've made an infinite loop. Choose a solution (1st one is preferred)

  • don't use traceroute and nmap as function name
  • use the full path of /usr/bin/traceroute and /usr/bin/nmap
Sign up to request clarification or add additional context in comments.

Comments

1

The bit immediately after 'read ip' isn't necessary, as it actually doesn't do anything (so far as I can tell).

#!/bin/bash
echo "Usage:"
echo -n "Please enter t/n"
read o
echo -n "IP"
read ip
if [[ "$o" = "t" ]]
then
  traceroute $ip
elif [[ "$o" = "n" ]]
then
  nmap -T4 -A -v $ip
else
  echo "Usage:"
  echo "Please enter t/n"
  exit 1
fi

The above amended code works but could do with some formatting to make it look a little nicer.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.