/b/ryce
December 22nd, 2011, 02:11 AM
Here is my first bash script ever (aside from the obligatory "Hello, world!" one :) )
I originally got to the first challenge, read it, look up all sorts of guides on loops and finally get some code to work, only to try to post it and find that the thread is locked, so I decided to show it here and ask for help on my final error that I can't seem to fix that looks like it does nothing.
#!bin/bash
clear
x="99" #set variable for amount of beer.
y="bottles"
z="bottle"
while [ $x -gt 0 ]; do #while [ $var -(GreaterThan) 0]
echo "$x $y of beer on the wall, $x $y of beer."
let x=x-1 #take a bottle away.
#start grammar changes here
if [ $x = 1 ]; then
y=bottle
fi
if [ $x == 0 ]; then
y=bottles
fi
if [ $x == 0 ]; then
x="no more"
fi
echo "Take one down and pass it around, $x $y of beer on the wall."
sleep 6 #gives enough time to sing the song
done
echo "No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall."
read -p "Press enter to end the script..."
After the loop, but before the final echo, I get this error:
/home/bryce/bta/99_bottles.sh: line 6: [: too many arguments
I don't quite know how to get the error to go away, any help would be appreciated.
To play to the end just comment the line that says 'sleep 6'(line 20)
I originally got to the first challenge, read it, look up all sorts of guides on loops and finally get some code to work, only to try to post it and find that the thread is locked, so I decided to show it here and ask for help on my final error that I can't seem to fix that looks like it does nothing.
#!bin/bash
clear
x="99" #set variable for amount of beer.
y="bottles"
z="bottle"
while [ $x -gt 0 ]; do #while [ $var -(GreaterThan) 0]
echo "$x $y of beer on the wall, $x $y of beer."
let x=x-1 #take a bottle away.
#start grammar changes here
if [ $x = 1 ]; then
y=bottle
fi
if [ $x == 0 ]; then
y=bottles
fi
if [ $x == 0 ]; then
x="no more"
fi
echo "Take one down and pass it around, $x $y of beer on the wall."
sleep 6 #gives enough time to sing the song
done
echo "No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall."
read -p "Press enter to end the script..."
After the loop, but before the final echo, I get this error:
/home/bryce/bta/99_bottles.sh: line 6: [: too many arguments
I don't quite know how to get the error to go away, any help would be appreciated.
To play to the end just comment the line that says 'sleep 6'(line 20)