8 Replies - 2901 Views - Last Post: 08 October 2012 - 08:39 PM Rate Topic: -----

#1 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 247
  • Joined: 29-November 08

Worst Bash Script I've Ever Seen

Posted 23 February 2012 - 08:15 PM

This Nightmere comes to you from [[username removed]] I have no idea how he got this or figured this would be a good idea to play blackjack but here is the scariest bash script I've ever seen you have been warned

#!/bin/bash

# Blackjack.sh
# 
#
# Created by [[name removed]] on 6/28/10.
# Copyright 2010 Enginering. All rights reserved.


Set_settings () {

clear

Final_Base_Card_Value=0

#Card Values
value_carddraw_1=0
value_carddraw_2=0
value_carddraw_3=0
value_carddraw_4=0
value_carddraw_5=0
value_carddraw_6=0
value_carddraw_7=0
value_carddraw_8=0

#You have no cards to begin with
card_1_is=0
card_2_is=0
card_3_is=0
card_4_is=0
card_5_is=0
card_6_is=0
card_7_is=0
card_8_is=0
card_9_is=0
card_10_is=0
card_11_is=0


}

DrawCard_1 () {
RandomNumber=`expr '(' $RANDOM '*' 20 / 32767 ')' + 1` 
#echo "$RandomNumber"
if [ $value_carddraw_1 = 0 ]
then

if [ "$RandomNumber" = 3 ] || [ "$RandomNumber" = 5 ]
then
	card_2_is=1
	echo "You have a one"
	value_carddraw_1=1
else
	if [ "$RandomNumber" = 1 ] || [ "$RandomNumber" = 4 ]
	then
		card_5_is=1
		echo "You have a five"
		value_carddraw_1=5
	else
		if [ "$RandomNumber" = 2 ] || [ "$RandomNumber" = 6 ]
		then
			card_8_is=1
			echo "You have a eight"
			value_carddraw_1=8
		else
			if [ "$RandomNumber" = 7 ] || [ "$RandomNumber" = 9 ]
			then
				card_1_is=1
				echo "You have a one"
				value_carddraw_1=1
			else
				if [ "$RandomNumber" = 8 ] || [ "$RandomNumber" = 10 ]
				then
					card_3_is=1
					echo "You have a three"
					value_carddraw_1=3
				else
					if [ "$RandomNumber" = 15 ] || [ "$RandomNumber" = 18 ]
					then
						card_7_is=1
						echo "You have a seven"
						value_carddraw_1=7
					else
						if [ "$RandomNumber" = 14 ] || [ "$RandomNumber" = 17 ]
						then
							card_10_is=1
							echo "You have a Face Card"
							value_carddraw_1=10
						else
							if [ "$RandomNumber" = 13 ] || [ "$RandomNumber" = 15 ]
							then
								card_9_is=1
								echo "You have a nine"
								value_carddraw_1=9
							else
								if [ "$RandomNumber" = 12 ] || [ "$RandomNumber" = 11 ]
								then
									card_4_is=1
									echo "You have a four"
									value_carddraw_1=4
								else
									if [ "$RandomNumber" = 18 ] || [ "$RandomNumber" = 16 ]
									then
										card_6_is=1
										echo "You have a six"
										value_carddraw_1=6
									else
										if [ "$RandomNumber" = 19 ] || [ "$RandomNumber" = 20 ]
										then
											card_11_is=1
											echo "You have an Ace"
											value_carddraw_1=11
										
										fi
									fi
								fi
							fi
						fi
					fi
				fi
			fi
		fi
	fi
fi

else
	if [ $value_carddraw_2 = 0 ]
	then
		DrawCard_2
	else
		if [ $value_carddraw_3 = 0 ]
		then
			DrawCard_3
		else
			if [ $value_carddraw_4 = 0 ]
			then
				DrawCard_4
			fi
		fi
		
	fi
	

fi

}


DrawCard_2 () {
RandomNumber=`expr '(' $RANDOM '*' 20 / 32767 ')' + 1` 
#echo "$RandomNumber"
if [ "$RandomNumber" = 3 ] || [ "$RandomNumber" = 5 ]
then
	card_2_is=1
	echo "You have a one"
	value_carddraw_2=1
else
	if [ "$RandomNumber" = 1 ] || [ "$RandomNumber" = 4 ]
	then
		card_5_is=1
		echo "You have a five"
		value_carddraw_2=5
	else
		if [ "$RandomNumber" = 2 ] || [ "$RandomNumber" = 6 ]
		then
			card_8_is=1
			echo "You have a eight"
			value_carddraw_2=8
		else
			if [ "$RandomNumber" = 7 ] || [ "$RandomNumber" = 9 ]
			then
				card_1_is=1
				echo "You have a one"
				value_carddraw_2=1
			else
				if [ "$RandomNumber" = 8 ] || [ "$RandomNumber" = 10 ]
				then
					card_3_is=1
					echo "You have a three"
					value_carddraw_2=3
				else
					if [ "$RandomNumber" = 15 ] || [ "$RandomNumber" = 18 ]
					then
						card_7_is=1
						echo "You have a seven"
						value_carddraw_2=7
					else
						if [ "$RandomNumber" = 14 ] || [ "$RandomNumber" = 17 ]
						then
							card_10_is=1
							echo "You have a Face Card"
							value_carddraw_2=10
						else
							if [ "$RandomNumber" = 13 ] || [ "$RandomNumber" = 15 ]
							then
								card_9_is=1
								echo "You have a nine"
								value_carddraw_2=9
							else
								if [ "$RandomNumber" = 12 ] || [ "$RandomNumber" = 11 ]
								then
									card_4_is=1
									echo "You have a four"
									value_carddraw_2=4
								else
									if [ "$RandomNumber" = 18 ] || [ "$RandomNumber" = 16 ]
									then
										card_6_is=1
										echo "You have a six"
										value_carddraw_2=6
									else
										if [ "$RandomNumber" = 19 ] || [ "$RandomNumber" = 20 ]
										then
											card_11_is=1
											echo "You have an Ace"
											value_carddraw_2=11
										
										fi
									fi
								fi
							fi
						fi
					fi
				fi
			fi
		fi
	fi
fi
}

DrawCard_3 () {
RandomNumber=`expr '(' $RANDOM '*' 20 / 32767 ')' + 1` 
#echo "$RandomNumber"
if [ "$RandomNumber" = 3 ] || [ "$RandomNumber" = 5 ]
then
	card_2_is=1
	echo "You have a one"
	value_carddraw_3=1
else
	if [ "$RandomNumber" = 1 ] || [ "$RandomNumber" = 4 ]
	then
		card_5_is=1
		echo "You have a five"
		value_carddraw_3=5
	else
		if [ "$RandomNumber" = 2 ] || [ "$RandomNumber" = 6 ]
		then
			card_8_is=1
			echo "You have a eight"
			value_carddraw_3=8
		else
			if [ "$RandomNumber" = 7 ] || [ "$RandomNumber" = 9 ]
			then
				card_1_is=1
				echo "You have a one"
				value_carddraw_3=1
			else
				if [ "$RandomNumber" = 8 ] || [ "$RandomNumber" = 10 ]
				then
					card_3_is=1
					echo "You have a three"
					value_carddraw_3=3
				else
					if [ "$RandomNumber" = 15 ] || [ "$RandomNumber" = 18 ]
					then
						card_7_is=1
						echo "You have a seven"
						value_carddraw_3=7
					else
						if [ "$RandomNumber" = 14 ] || [ "$RandomNumber" = 17 ]
						then
							card_10_is=1
							echo "You have a Face Card"
							value_carddraw_3=10
						else
							if [ "$RandomNumber" = 13 ] || [ "$RandomNumber" = 15 ]
							then
								card_9_is=1
								echo "You have a nine"
								value_carddraw_3=9
							else
								if [ "$RandomNumber" = 12 ] || [ "$RandomNumber" = 11 ]
								then
									card_4_is=1
									echo "You have a four"
									value_carddraw_3=4
								else
									if [ "$RandomNumber" = 18 ] || [ "$RandomNumber" = 16 ]
									then
										card_6_is=1
										echo "You have a six"
										value_carddraw_3=6
									else
										if [ "$RandomNumber" = 19 ] || [ "$RandomNumber" = 20 ]
										then
											card_11_is=1
											echo "You have an Ace"
											value_carddraw_3=11
										
										fi
									fi
								fi
							fi
						fi
					fi
				fi
			fi
		fi
	fi
fi	
}

DrawCard_4 () {
RandomNumber=`expr '(' $RANDOM '*' 20 / 32767 ')' + 1` 
#echo "$RandomNumber"
if [ "$RandomNumber" = 3 ] || [ "$RandomNumber" = 5 ]
then
	card_2_is=1
	echo "You have a one"
	value_carddraw_4=1
else
	if [ "$RandomNumber" = 1 ] || [ "$RandomNumber" = 4 ]
	then
		card_5_is=1
		echo "You have a five"
		value_carddraw_4=5
	else
		if [ "$RandomNumber" = 2 ] || [ "$RandomNumber" = 6 ]
		then
			card_8_is=1
			echo "You have a eight"
			value_carddraw_4=8
		else
			if [ "$RandomNumber" = 7 ] || [ "$RandomNumber" = 9 ]
			then
				card_1_is=1
				echo "You have a one"
				value_carddraw_4=1
			else
				if [ "$RandomNumber" = 8 ] || [ "$RandomNumber" = 10 ]
				then
					card_3_is=1
					echo "You have a three"
					value_carddraw_4=3
				else
					if [ "$RandomNumber" = 15 ] || [ "$RandomNumber" = 18 ]
					then
						card_7_is=1
						echo "You have a seven"
						value_carddraw_4=7
					else
						if [ "$RandomNumber" = 14 ] || [ "$RandomNumber" = 17 ]
						then
							card_10_is=1
							echo "You have a Face Card"
							value_carddraw_4=10
						else
							if [ "$RandomNumber" = 13 ] || [ "$RandomNumber" = 15 ]
							then
								card_9_is=1
								echo "You have a nine"
								value_carddraw_4=9
							else
								if [ "$RandomNumber" = 12 ] || [ "$RandomNumber" = 11 ]
								then
									card_4_is=1
									echo "You have a four"
									value_carddraw_4=4
								else
									if [ "$RandomNumber" = 18 ] || [ "$RandomNumber" = 16 ]
									then
										card_6_is=1
										echo "You have a six"
										value_carddraw_4=6
									else
										if [ "$RandomNumber" = 19 ] || [ "$RandomNumber" = 20 ]
										then
											card_11_is=1
											echo "You have an Ace"
											value_carddraw_4=11
										
										fi
									fi
								fi
							fi
						fi
					fi
				fi
			fi
		fi
	fi
fi	
}



										
Sum_Math() {

final_value=`expr $value_carddraw_1 + $value_carddraw_2 + $value_carddraw_3 + $value_carddraw_4 + $value_carddraw_5 + $value_carddraw_6 + $value_carddraw_7 + $value_carddraw_8`
echo "Your total is "$final_value"."
if [ $final_value > 21 ]
then
	echo "Bust"
	exit 1
fi
Main
}


Main() {
echo "[Dealer] >> Would you like a hit? y/n"
printf "[You] << "
read sumuserimput
if [ "$sumuserimput" = "y" ] || [ "$sumuserimput" = "Y" ]
then
	DrawCard_1
	Sum_Math
	Main
	
fi
if [ $thisissumdumbusersimput = "n" ] || [ $thisissumdumbusersimput = "N" ]
then
	Stay
fi
}

#Dealer's AI
Stay() {
echo "Not Integrated"
}


Set_settings
#Base Cards
DrawCard_1
DrawCard_2
Sum_Math


This post has been edited by BenignDesign: 09 October 2012 - 12:08 PM
Reason for edit:: Removed username of responsible member at member's request.


Is This A Good Question/Topic? 0
  • +

Replies To: Worst Bash Script I've Ever Seen

#2 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5178
  • View blog
  • Posts: 26,870
  • Joined: 10-May 07

Re: Worst Bash Script I've Ever Seen

Posted 23 February 2012 - 08:18 PM

fi, fi, fi, fi, fi, fi, fi, fi.... you're doing it wrong!

Quote

if [ $value_carddraw_2 = 0 ]

Erm, is this even correct? I assume this isn't a string, so it should be -eq not =. Does this even work or always return false?

I also quite enjoy the here again/gone again indenting usage.
Was This Post Helpful? 0
  • +
  • -

#3 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 247
  • Joined: 29-November 08

Re: Worst Bash Script I've Ever Seen

Posted 23 February 2012 - 08:23 PM

I'm not sure it's been a while since I've worked with Linux/ Unix in a while but I'm pretty sure you need -eq with numeric and = with strings
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5178
  • View blog
  • Posts: 26,870
  • Joined: 10-May 07

Re: Worst Bash Script I've Ever Seen

Posted 23 February 2012 - 08:27 PM

Yes, that's exactly correct. & if it were strings (using =) then the conditional argument should be wrapped in a quotation sandwich.
Was This Post Helpful? 0
  • +
  • -

#5 paintballer  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 7
  • Joined: 17-March 12

Re: Worst Bash Script I've Ever Seen

Posted 22 March 2012 - 06:27 AM

what language is this in???java? i cant reconize it
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5178
  • View blog
  • Posts: 26,870
  • Joined: 10-May 07

Re: Worst Bash Script I've Ever Seen

Posted 22 March 2012 - 06:42 AM

View Postpaintballer, on 22 March 2012 - 09:27 AM, said:

what language is this in???

Bash is a shell scripting language. It's right in the title.
Was This Post Helpful? 0
  • +
  • -

#7 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7564
  • View blog
  • Posts: 12,689
  • Joined: 19-March 11

Re: Worst Bash Script I've Ever Seen

Posted 23 March 2012 - 08:23 AM

Someone needs a kicking!


One good thing about it, though. You won't have any luck counting cards against this casino!



echo "[Dealer] >> Would you like a hit? y/n"



Dude, I think you should lay off that stuff a little...
Was This Post Helpful? 3
  • +
  • -

#8 EvanSchoffstall  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 17
  • Joined: 23-May 10

Re: Worst Bash Script I've Ever Seen

Posted 05 September 2012 - 10:27 AM

Yeah, that's pretty awful.

This post has been edited by EvanSchoffstall: 05 September 2012 - 10:41 AM

Was This Post Helpful? 0
  • +
  • -

#9 sas1ni69  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 431
  • Joined: 04-December 08

Re: Worst Bash Script I've Ever Seen

Posted 08 October 2012 - 08:39 PM

View Postjon.kiparsky, on 23 March 2012 - 11:23 PM, said:

Someone needs a kicking!


One good thing about it, though. You won't have any luck counting cards against this casino!



echo "[Dealer] >> Would you like a hit? y/n"



Dude, I think you should lay off that stuff a little...


Hahaha I didn't notice that til you brought it up! Must be high as hell if the dealer is offering you hits and shit.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1