LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Problem with bash script. (http://www.linuxquestions.org/questions/programming-9/problem-with-bash-script-385309/)

cheater1034 11-21-2005 07:19 PM

Problem with bash script.
 
Hello,
I am working on some gentoo install scripts, there are 2 separate ones.

Here is part of the first script
Code:

echo "Enter your network interface (probally eth0)"
read $IFACE
net-setup $IFACE
echo "Please enter the location of your hard drive (first ide hard drive /dev/hda second /dev/hdb etc.):"
read $HARDDRIVE
echo "Do you want to run CFDISK? (ncurses based partition program) (y/n)"
read $CFDISK
if  [ "$CFDISK" == y ]
  then
      cfdisk $HARDDRIVE
fi
if [ "$CFDISK" == n ]
  then
      quit
fi

I execute it, then it asks about CFDISK, i input, y - and it just skips over to the next part, then I try inputting n, and it skips over to the next part (like supposed to)

The problem is, when I input, y, it is supposed to execute CFDISK on the hard drive I entered?

Did I write something wrong - the simplest of help is appreciated :)

Brian1 11-21-2005 08:09 PM

You might specify where cfdisk is.
Also are you running script as a user?
If so does the user account have access to cfdisk?

Brian1

uberNUT69 11-21-2005 08:33 PM

try
Code:

read CFDISK
etc

cheater1034 11-21-2005 09:44 PM

No, I tried /sbin/cfdisk and it didnt work.

It appears it isn't even acknowledging that command?

uberNUT69 11-21-2005 10:03 PM

ahem:
remove the $ from your READ lines

cheater1034 11-21-2005 10:29 PM

No it didn't work, does the same thing... I dont get any output from doing it manually it just skips, heres what I have on it now... does the same thing :(

Code:

echo "Enter your network interface (probally eth0)"
read IFACE
net-setup IFACE
echo "Running dhcpcd"
dhcpcd
echo "Invoking ifconfig"
ifconfig
echo "If the network is NOT setup properly, cancel the script with ctrl+z and try manual configuration"
echo "Please enter the location of your hard drive (first ide hard drive /dev/hda second /dev/hdb etc.):"
read HARDDRIVE
echo "Do you want to run CFDISK? (ncurses based partition program) (y/n)"
read CFDISK
if  [ "CFDISK" == "y" ]
    then
      cfdisk HARDDRIVE
fi
if [ "CFDISK" == "n" ]
  then
      quit
fi

if there is something I'm doing wrong, or is there a better method of doing this?

I tried removing the quotes, etc - hasn't worked yet :(

thanks for the quick responses

uberNUT69 11-21-2005 10:45 PM

yes it did work ... you didn't read my post correctly
I said to remove the $ from the READ lines, not the if conditions
Code:

if  [ $CFDISK == y ]
is the same as
Code:

if  [ "$CFDISK" == y ]
and rather than wasting everyones time! :) try debugging your own code like this:
Code:

echo "Enter your network interface (probally eth0)"
read IFACE
echo DEBUG IFACE $IFACE
#net-setup IFACE
echo "Running dhcpcd"
#dhcpcd
echo "Invoking ifconfig"
#ifconfig
echo "If the network is NOT setup properly, cancel the script with ctrl+z and try manual configuration"
echo "Please enter the location of your hard drive (first ide hard drive /dev/hda second /dev/hdb etc.):"
read HARDDRIVE
echo DEBUG HARDDRIVE $HARDDRIVE
echo "Do you want to run CFDISK? (ncurses based partition program) (y/n)"
read CFDISK
echo DEBUG CFDISK $CFDISK
if  [ "$CFDISK" == y ]
    then
      echo "DEBUG executing: cfdisk $HARDDRIVE"
      cfdisk HARDDRIVE
fi
if [ "CFDISK" == "n" ]
  then
      quit
fi


cheater1034 11-21-2005 11:11 PM

ahh sorry :) Thankyou very much it did work

jschiwal 11-21-2005 11:19 PM

You are missing the "$" symbol in the line "cfdisk HARDDRIVE"

This test program worked for me:
Code:

#!/bin/bash
echo -n "Enter the harddrive: "
read HARDDRIVE
echo "Do you want to run CFDISK? (ncurses based partition program) (y/n)"
read CFDISK
if  [ "$CFDISK" == "y" ]
    then
      cfdisk $HARDDRIVE
fi

Remember that you need to start the harddrive entry with "/dev/".

uberNUT69 11-21-2005 11:29 PM

You are missing the "$" symbol in the line "cfdisk HARDDRIVE"

lol, oops, sorry missed that one
[excuse]I don't have partition tables on my (Xen) test machine[/excuse]


All times are GMT -5. The time now is 07:28 PM.