Sponsored Content
Full Discussion: POSIX compliance...
Operating Systems OS X (Apple) POSIX compliance... Post 302976755 by wisecracker on Tuesday 5th of July 2016 04:22:50 PM
Old 07-05-2016
POSIX compliance...

Thanks to all you guys about posix compliance I have learnt an enormous amount over the last few days.
I have written a program that is an Egg Timer with simple animation.
I now realise how sophisticated 'bash' is compared to full posix compliance.
The code below has passed all of the tests from ShellCheck and boy have I found out a lot from it.
So the only way for me to learn was to create this program...
Enjoy...
(No doubt the big guns will find a better way... ;o) )
Code:
#!/bin/sh
# Egg_Timer.sh
# Fully POSIX compliant.
# Tested on OSX 10.7.5, OSX 10.11.3, Ubuntu64 and CygWin64 on Windows 8.1.
# It has fully passed CheckShell's tests. Tuesday July 5th, 2016.
# Public Domain, 2016, B.Walker, G0LCU.

mins=3
secs=0
fsecs=1.00000
keyboard="?"
width=12
horiz=36
vert=3
spaces='              '
stars='**************'
char=0
platform=$( uname )

# Generate the sinewave beep.
if [ ! -e "/tmp/beep.wav" ]
then
	> /tmp/beep.wav
	printf "\122\111\106\106\144\037\000\000\127\101\126\105\146\155\164\040\020\000\000\000\001\000\001\000\100\037\000\000\100\037\000\000\001\000\010\000\144\141\164\141\100\037\000\000" >> /tmp/beep.wav
	while [ $char -le 999 ]
	do
		printf "\200\046\000\046\177\331\377\331" >> /tmp/beep.wav
		char=$(( char + 1 ))
	done
fi

clrscn()
{
	# A default CygWin and CygWin64 install does not have 'clear' nor 'tput'!
	printf "\033c\033[0m\033[2J\033[H"
}

display()
{
	clrscn
	echo '	  At a glance Egg Timer, Public Domain, 2016, B.Walker, G0LCU.
				   ____________  
				 / ************ \ 
				||**************|| 
				 \**************/ 
				  \************/ 
				   \**********/ 
				    \********/ 
				     \******/ 
				      \****/ 
				       \**/ 
				        || 
				       /..\ 
				      / .. \ 
				     /  ..  \ 
				    /   ..   \ 
				   /    ..    \ 
				  /     ..     \ 
				 /      ..      \ 
				||      ..      || 
				 \      **      / 
__________________________________==============________________________________'
	echo "			      Time set to $secs seconds."
}

set_time()
{
	clrscn
	echo ''
	echo '		Enter the timer time in minutes first and seconds next.'
	echo ''
	printf 'Enter the number of minutes:- '
	read -r mins
	echo ''
	printf 'Enter the number of seconds:- '
	read -r secs
	echo ''
	printf "Timer set to %s? minutes and %s? seconds, are these correct? (Y/N):- " "$mins" "$secs"
	read -r keyboard
	if [ "$keyboard" = "N" ] || [ "$keyboard" = "n" ]
	then
		set_time
	fi

	# Check for typos and other errors.
	case $mins in
		''|*[!0-9]*) mins=3 ;;
	esac
	case $secs in
		''|*[!0-9]*) secs=0 ;;
	esac
	if [ $mins -gt 59 ] || [ $mins -lt 0 ]
	then
		mins=59
	fi
	if [ $secs -gt 59 ] || [ $secs -lt 0 ]
	then
		secs=59
	fi
	secs=$(( ( mins * 60 ) + secs ))
	if [ $secs -lt 15 ]
	then
		secs=15
	fi
	# A default CygWin or CygWin64 install does not have 'bc' nor 'dc'.
	fsecs=$( awk -v fp=$secs 'BEGIN { print ( fp / 17 ); }' )
}

# Main loop.
while true
do
	set_time
	horiz=36
	keyboard="?"
	width=12
	spaces='              '
	stars='**************'
	display
	sleep "$fsecs"
	printf "\033[3;36f      \033[24;1f"
	for vert in 3 4 5
	do
		printf "\033[%u;35f%s\033[24;1f" "$(( 24 - vert ))" "$stars"
		printf "\033[%u;35f%s\033[24;1f" "$vert" "$spaces"
		sleep "$fsecs"
		printf "\033[%u;41f**\033[24;1f" "$(( 23 - vert ))"
		sleep "$fsecs"
	done
	for vert in 6 7 8 9 10
	do
		char=$( awk -v star="$stars" -v wide="$width" 'BEGIN { print substr(star,1,wide); }' )
		printf "\033[%u;%uf%s\033[24;1f" "$(( 24 - vert ))" "$horiz" "$char"
		char=$( awk -v space="$spaces" -v wide="$width" 'BEGIN { print substr(space,1,wide); }' )
		printf "\033[%u;%uf%s\033[24;1f" "$vert" "$horiz" "$char"
		sleep "$fsecs"
		printf "\033[%u;41f**\033[24;1f" "$(( 23 - vert ))"
		sleep "$fsecs"
		horiz=$(( horiz + 1 ))
		width=$(( width - 2 ))
	done
	printf "\033[11;%uf  \033[24;1f" "$horiz"
	for char in 1 2 3
	do
		if [ "$platform" = "Darwin" ]
		then
			afplay /tmp/beep.wav > /dev/null 2>&1
		else
			aplay /tmp/beep.wav > /dev/null 2>&1
		fi
		if [ "$( awk -v name="$platform" 'BEGIN { print substr(name,1,6); } ')" = "CYGWIN" ]
		then
			cat /tmp/beep.wav > /dev/dsp
		fi
	done
	printf 'Run again? (Y/N):- '
	read -r keyboard
	if [ "$keyboard" = "N" ] || [ "$keyboard" = "n" ]
	then
		break
	fi
done
clrscn
exit 0
# Egg_Timer.sh end.

 

5 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

sudo & Sox compliance

Hello, I am trying to convince my boss to stop allowing our users to login as root (superuser). Currently our users login to our unix server with their own account, then as needed, they will do an su and put in the root password. This scares me, for a bunch of reasons. Mainly, one is that we... (1 Reply)
Discussion started by: rwallaceisg
1 Replies

2. UNIX for Dummies Questions & Answers

man synopsis standard compliance

In different online sources, I found bits and pieces of information about those square and angular brackets and pipes. From what I have read, I can conclude it looks like this: 1. Options outside any brackets are mandatory 2. Options inside these < .. > are mandatory too 3. Options inside ... (4 Replies)
Discussion started by: vkleban
4 Replies

3. Cybersecurity

PCI DSS Compliance : Insecure Communication Has Been Detected

From the nessus scanner tool report i got below vulnerability PCI DSS Compliance : Insecure Communication Has Been Detected http://www.tenable.com/plugins/index.php?view=single&id=56208 As per the description given in above link - I am not able to understand How to find insecure port... (2 Replies)
Discussion started by: saurabh84g
2 Replies

4. Red Hat

Looking for PCI Compliance tool for Redhat Lix.

Hi i am in new to Linux world . I have been assigned to a project to find out a tool that will fulfill the PCI compliance for Linux servers for Audit process. anyone have any recommendation on that. Do Rad hat have any native application or plug-ins which we can use for that. (1 Reply)
Discussion started by: sahasuman
1 Replies

5. HP-UX

Password compliance setting

I need to set password compliance for some servers in my company. However, the requirements are that we need to set different password policies for 3 different user groups within the company. These are : System Users: i.e root, etc Batch/Application Users: oracle, bscs, etc Standard User:... (0 Replies)
Discussion started by: anaigini45
0 Replies
All times are GMT -4. The time now is 06:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy