Hackerboard Wiki HaboBlog
Hackerboard bei Facebook Hackerboard bei Google+ Hackerboard bei Twitter

[HaBo]

 
Linux/UNIX Linuxverfechter finden hier Weggefährten.

Shell Script Probleme

Diskussion: Shell Script Probleme im Forum Linux/UNIX, in der Kategorie Operating Systems; Anzeige Hi, ich habe eine Date, die so aussieht: Code: (-514,519) und ich möchte in getrennte Variablen die -514 und ...

Antwort
Alt 09.07.08, 12:02   #1 (permalink)
Senior Member
 
Registriert seit: 26.03.06
Serow Leistung: 8086
Likes: 16
Shell Script Probleme

Anzeige

Hi,

ich habe eine Date, die so aussieht:

Code:
(-514,519)
und ich möchte in getrennte Variablen die -514 und die 519 haben.

Soweit bin ich grad :D
Code:
position=`cat $CALIBRATE_FILE'
positionX=...
positionY=...
Gut oder? :D Kann mir da jemand helfen? Ich hab "sed" gefunden aber wie benutze ich das jetzt? Programmiere Shell seit ... heute :D
Serow ist offline   Mit Zitat antworten
Alt 09.07.08, 12:08   #2 (permalink)
Moderator
 
Benutzerbild von xeno
 
Registriert seit: 09.09.04
xeno Leistung: Pentium Ixeno Leistung: Pentium I
xeno eine Nachricht über ICQ schicken
Likes: 76
Standard

so in etwa?

echo "(-514,519)" | cut -d , -f 1 | sed "s/(//"
echo "(-514,519)" | cut -d , -f 2 | sed "s/)//"

müsstest du halt noch umbauen damits auf deine bedürfnisse passt.
xeno ist offline   Mit Zitat antworten
   
HaBOT
 
- Anzeige -

Werbung ist gerade online    
Alt 09.07.08, 13:13   #3 (permalink)
Moderator
 
Registriert seit: 30.06.08
Chromatin Leistung: K 6-3Chromatin Leistung: K 6-3Chromatin Leistung: K 6-3Chromatin Leistung: K 6-3
Likes: 227
Standard

Wenn du bash hast sollte Folgendes gehen

Code:
position=`cat $CALIBRATE_FILE `

AR=( `echo $position  |  sed "s/(//" | sed "s/)//" | awk -F, '{print $1 " "$2}'` )
Zugriff aufs Array mit:

Code:
${AR[0]}, 
${AR[1]},
usw..
__________________
Wenn ein Gesetz nicht gerecht ist, dann geht die Gerechtigkeit vor dem Gesetz!

Habo Blog - http://blog.hackerboard.de/
Chromatin ist offline   Mit Zitat antworten
Alt 09.07.08, 20:04   #4 (permalink)
Senior Member
Themenstarter
 
Registriert seit: 26.03.06
Serow Leistung: 8086
Likes: 16
Standard

Danke schonmal. Ich habs mit der sed Variante gelöst:

Code:
#!/bin/sh

LAPTOP_MODE_FILE=/etc/tabletmode
CALIBRATE_FILE=/sys/devices/platform/hdaps/calibrate
POSITION_FILE=/sys/devices/platform/hdaps/position

MODE_TABLET=tablet
MODE_LAPTOP=laptop



xrandr_rotate=normal
wacom_rotate=0

echo "Reading calibration file..."
content=`cat $CALIBRATE_FILE`
calibX=`echo $content | cut -d , -f 1 | sed "s/(//"`
calibY=`echo $content | cut -d , -f 1 | sed "s/(//"`
echo "Calibration:" $calibX $calibY

echo "Starting main loop"
while :
do
	sleep 1

	laptopMode=`cat $LAPTOP_MODE_FILE`
	echo $laptopMode

	if [ $laptopMode == $MODE_LAPTOP ]
	then
		xrandr_rotate=normal
		wacom_rotate=0
	else
		echo "Reading position file..."
		content=`cat $POSITION_FILE`
		posX=`echo $content | cut -d , -f 1 | sed "s/(//"`
		posY=`echo $content | cut -d , -f 2 | sed "s/)//"`
		echo "Position:" $posX $posY

		absX=0
		absY=0		

		if [ $posX -le 0 ]
		then
			absX=`echo $(( -1*$posX ))`
		else
			absX=$posY
		fi

		if [ $posY -le 0 ]
		then
			absY=`echo $(( -1*$posY ))`
		else
			absY=$posY
		fi

		echo "Absolute Position" $absX $absY

		if [ absY > absX ]
		then
			if [ $posY > 0 ]
			then
				xrandr_rotate=left
				wacom_rotate=2
			else
				xrandr_rotate=right
				wacom_rotate=1
			fi
		else
			if [ $posX < 0 ]
			then
				xrandr_rotate=normal
				wacom_rotate=0
			else
				xrandr_rotate=inverted
				wacom_rotate=3
			fi
		fi

		echo "XRAND ROTATE $xrandr_rotate"
		echo "XSETWACOM ROTATE $wacom_rotate"
	fi

done
Allerdings braucht das Script noch etwas debugging:

Code:
mathias@apprentice:~/Apps/scripts/rotate$ ./autorotate.sh
Reading calibration file...
Calibration: 0 0
Starting main loop
laptop
[: 82: ==: unexpected operator
Reading position file...
Position: -513 519
Absolute Position 513 519
XRAND ROTATE left
XSETWACOM ROTATE 2
Warum der Fehler in Zeile 82 auftaucht ist mir ein Rätsel. Allerdings kommt er von der If-Abfrage denke ich:
Code:
if [ $laptopMode == $MODE_LAPTOP ]
Zum Vergleich von Strings hab ich mir einen Test geschrieben:
Code:
STR1="test"
STR2="test"

if [ $STR1 == $STR2 ]
then
       echo "MATCH"
else
       echo "NO MATCH"
fi
Hier kommt immer "MATCH" spricht der Vergleich klappt. Aber in obigem Script mach ich es doch genauso ?!?!

mfg
serow
Serow ist offline   Mit Zitat antworten
Alt 09.07.08, 20:24   #5 (permalink)
Senior Member
 
Benutzerbild von lookshe
 
Registriert seit: 10.03.07
lookshe Leistung: 8086
Likes: 19
Standard

Code:
if [ $laptopMode == $MODE_LAPTOP ]
zu:

Code:
if [ "$laptopMode" = "$MODE_LAPTOP" ]

dann klappts auch mit dem Nachbarn... ähm dem Vergleich.
lookshe ist offline   Mit Zitat antworten
Alt 09.07.08, 23:04   #6 (permalink)
Senior Member
Themenstarter
 
Registriert seit: 26.03.06
Serow Leistung: 8086
Likes: 16
Standard

Sehr schön, danke. Shell ist etwas seltsam wenn man von Java kommt ...

Hier mein fertiges Script. Ihr durft es gerne selbst verwenden, allerdings poste ich es in erster Linie um ein paar Verbesserungsvorschläge zu sammeln. Besonders was die CPU Belastung angeht. Die ist jetzt nicht soo wild, wär aber trotzdem schön, wann man da noch was schrauben könnte.
Code:
#!/bin/sh

LAPTOP_MODE_FILE=/etc/tabletmode
CALIBRATE_FILE=/sys/devices/platform/hdaps/calibrate
POSITION_FILE=/sys/devices/platform/hdaps/position

RESISTANCY=30

MODE_TABLET=tablet
MODE_LAPTOP=laptop

xrandr_rotate=normal
wacom_rotate=0

#echo "Reading calibration file..."
content=`cat $CALIBRATE_FILE`
calibX=`echo $content | cut -d , -f 1 | sed "s/(//"`
calibY=`echo $content | cut -d , -f 2 | sed "s/)//"`
#echo "Calibration:" $calibX $calibY

#echo "Starting main loop"
while :
do
	sleep 1

	laptopMode=`cat $LAPTOP_MODE_FILE`
	#echo $laptopMode

	if [ "$laptopMode" = "$MODE_LAPTOP" ]
	then
		xrandr_rotate=normal
		wacom_rotate=0
	else
		#echo "Reading position file..."
		content=`cat $POSITION_FILE`
		posX=`echo $content | cut -d , -f 1 | sed "s/(//"`
		posY=`echo $content | cut -d , -f 2 | sed "s/)//"`
		#echo "Position:" $posX $posY

		if [ $posX -le 0 ]
		then
			absX=`echo $(( -1*$posX ))`
		else
			absX=$posY
		fi

		if [ $posY -le 0 ]
		then
			absY=`echo $(( -1*$posY ))`
		else
			absY=$posY
		fi

		#echo "Absolute Position" $absX $absY

		minX=$(($calibX-$RESISTANCY))
		minY=$(($calibY-$RESISTANCY))
		maxX=$(($calibX+$RESISTANCY))
		maxY=$(($calibX+$RESISTANCY))


		xOutOfTollerance=0	
		xOutOfTollerance=1			

		if [ $posX -lt $minX ]
		then
			xrandr_rotate=left
			wacom_rotate=2
		else
			if [ $posX -gt $maxX ]
			then
				xrandr_rotate=right
				wacom_rotate=1
			else
				if [ $posY -lt $minY ]
				then
					xrandr_rotate=normal
					wacom_rotate=0
				else
					if [ $posY -gt $maxY ]
					then
						xrandr_rotate=inverted
						wacom_rotate=3
					fi
				fi
			fi
		fi
	fi

	echo `xrandr --output LVDS --rotation $xrandr_rotate`
	echo `xsetwacom set stylus Rotate $wacom_rotate`
done
Was das Script macht:
Es liest die HDAPS Sensoren aus und dreht den Bildschirm (xrandr ... --rotate) und die wacom settinsg gleich mit. Es ne schöne Sache besondert für Tablet PCs


cu
serow
Serow ist offline   Mit Zitat antworten
Alt 10.07.08, 00:42   #7 (permalink)
Member of Honour
 
Benutzerbild von beavisbee
 
Registriert seit: 22.02.07
beavisbee Leistung: Pentium IIIbeavisbee Leistung: Pentium IIIbeavisbee Leistung: Pentium IIIbeavisbee Leistung: Pentium III
beavisbee eine Nachricht über ICQ schicken
Likes: 77
Standard

sehr schöne Idee, serow!
beavisbee ist offline   Mit Zitat antworten
Alt 10.07.08, 07:36   #8 (permalink)
Senior Member
Themenstarter
 
Registriert seit: 26.03.06
Serow Leistung: 8086
Likes: 16
Standard

Danke schön - hab heut Nach noch ein paar verbesserungen vorgenommen. z.B. die Berechnung von minX, maxX, ... aus der Schleife rausgenommen. Jetzt werden die xrandr und xsetwacom Kommandos nur ausgeführt wenns sie nötig sind:

Code:
#!/bin/sh

LAPTOP_MODE_FILE=/etc/tabletmode
CALIBRATE_FILE=/sys/devices/platform/hdaps/calibrate
POSITION_FILE=/sys/devices/platform/hdaps/position

RESISTANCY=30

MODE_TABLET=tablet
MODE_LAPTOP=laptop

xrandr_status=unknown
wacom_status=unknown
xrandr_rotate=normal
wacom_rotate=0

if [ "$1" = "off" ]
then
	echo `xrandr --output LVDS --rotation normal`
	echo `xsetwacom set stylus Rotate 0`
	echo `killall autorotate.sh`
	exit 0
fi

content=`cat $CALIBRATE_FILE`
calibX=`echo $content | cut -d , -f 1 | sed "s/(//"`
calibY=`echo $content | cut -d , -f 2 | sed "s/)//"`

minX=$(($calibX-$RESISTANCY))
minY=$(($calibY-$RESISTANCY))
maxX=$(($calibX+$RESISTANCY))
maxY=$(($calibY+$RESISTANCY))	

while :
do
	sleep 1

	laptopMode=`cat $LAPTOP_MODE_FILE`

	if [ "$laptopMode" = "$MODE_LAPTOP" ]
	then
		xrandr_rotate=normal
		wacom_rotate=0
	else
		content=`cat $POSITION_FILE`
		posX=`echo $content | cut -d , -f 1 | sed "s/(//"`
		posY=`echo $content | cut -d , -f 2 | sed "s/)//"`		

		if [ $posX -lt $minX ]
		then
			xrandr_rotate=left
			wacom_rotate=2
		else
			if [ $posX -gt $maxX ]
			then
				xrandr_rotate=right
				wacom_rotate=1
			else
				if [ $posY -lt $minY ]
				then
					xrandr_rotate=normal
					wacom_rotate=0
				else
					if [ $posY -gt $maxY ]
					then
						xrandr_rotate=inverted
						wacom_rotate=3
					fi
				fi
			fi
		fi
	fi

	if [ "$xrandr_status" != "$xrandr_rotate" -o "$wacom_status" != "$wacom_rotate" ]
	then
		echo `xrandr --output LVDS --rotation $xrandr_rotate`
		echo `xsetwacom set stylus Rotate $wacom_rotate`
		echo "ROTATE: $xrandr_status"
		xrandr_status=$xrandr_rotate
		wacom_status=$wacom_rotate
	fi
done
Serow ist offline   Mit Zitat antworten
Alt 10.07.08, 15:38   #9 (permalink)
 
Registriert seit: 22.10.05
farhaven Leistung: Z3
Likes: 3
Standard

Wenn ich mich nicht ganz irre, könntest du
Code:
content=`cat $POSITION_FILE`
posX=`echo $content | cut -d , -f 1 | sed "s/(//"`
posY=`echo $content | cut -d , -f 2 | sed "s/)//"`
ersetzen durch
Code:
posX=`cut -d , -f 1 < $POSITION_FILE | sed "s/(//"`
posY=`cut -d , -f 1 < $POSITION_FILE | sed "s/)//"`
das würde dann die UUOC entfernen. Bei
Code:
content=`cat $CALIBRATE_FILE`
calibX=`echo $content | cut -d , -f 1 | sed "s/(//"`
calibY=`echo $content | cut -d , -f 2 | sed "s/)//"`
würde ich dann analog dazu vorgehen, also
Code:
calibX=`cut -d , -f 1 < $POSITION_FILE | sed "s/(//"`
calibY=`cut -d , -f 2 < $POSITION_FILE | sed "s/)//"`
Zudem ist das echo bei
Code:
echo `xrandr --output LVDS --rotation normal`
echo `xsetwacom set stylus Rotate 0`
echo `killall autorotate.sh`
nicht nötig, es reicht, wenn die Befehle einfach so da stehen. Auch die ` sind dann nicht mehr von Nöten.

Das selbe trifft auch auf
Code:
echo `xrandr --output LVDS --rotation $xrandr_rotate`
echo `xsetwacom set stylus Rotate $wacom_rotate`
zu.

Von diesen kleinen "Ungeschliffenheiten" finde ich das Script aber besonderes für einen Anfänger sehr gelungen
farhaven ist offline   Mit Zitat antworten
Alt 10.07.08, 21:21   #10 (permalink)
Senior Member
Themenstarter
 
Registriert seit: 26.03.06
Serow Leistung: 8086
Likes: 16
Standard

Danke schön. Ist ja nicht das erstmal dass ich programmiere aber immerhin das erstmal mit shell Kann mir garnicht vorstellen wie man mit dieser sequentiellen Programierung was größeres hinzauber soll

Ich habe zu dem Script nocht was dazugebastelt, und zwar werden jetzt die Pfeiltasten, die sich auf meinem X61 Tablet am Bildschirm befinden, mit dem Bildschirm rotiert.

Code:
#!/bin/sh

LAPTOP_MODE_FILE=/etc/tabletmode
CALIBRATE_FILE=/sys/devices/platform/hdaps/calibrate
POSITION_FILE=/sys/devices/platform/hdaps/position
RESISTANCY=50

MODE_TABLET=tablet
MODE_LAPTOP=laptop

xrandr_status=normal
wacom_status=0
laptop_status=$MODE_LAPTOP
xrandr_rotate=normal
wacom_rotate=0

if [ "$1" = "off" ]
then
	xrandr --output LVDS --rotation normal
	xsetwacom set stylus Rotate 0
	killall autorotate.sh
	exit 0
fi

calibX=`cut -d , -f 1 < $CALIBRATE_FILE | sed "s/(//"`
calibY=`cut -d , -f 2 < $CALIBRATE_FILE | sed "s/)//"`

echo "Calibration: $calibX $calibY"

minX=$(($calibX-$RESISTANCY))
minY=$(($calibY-$RESISTANCY))
maxX=$(($calibX+$RESISTANCY))
maxY=$(($calibY+$RESISTANCY))	


while :
do
	sleep $1

	laptopMode=`cat $LAPTOP_MODE_FILE`

	if [ "$laptopMode" = "$MODE_LAPTOP" ]
	then
		echo "Computer is in Laptop Mode"
		xrandr_rotate=normal
		wacom_rotate=0
		laptop_status=$MODE_LAPTOP
	else
		echo "Computer is in Tablet Mode"	

		if [ "$laptop_status" = "$MODE_LAPTOP" ]
		then
			xrandr_rotate="inverted"
			wacom_rotate=3
			laptop_status=$MODE_TABLET
		fi
	
		posX=`cut -d , -f 1 < $POSITION_FILE | sed "s/(//"`
		posY=`cut -d , -f 2 < $POSITION_FILE | sed "s/)//"`		

		echo "$posX -> [ $minX : $maxX ]"
		echo "$posY -> [ $minY : $maxY ]"

		if [ $posX -lt $minX ]
		then
			xrandr_rotate=left
			wacom_rotate=2
		else
			if [ $posX -gt $maxX ]
			then
				xrandr_rotate=right
				wacom_rotate=1
			else
				if [ $posY -lt $minY ]
			then
					xrandr_rotate=normal
					wacom_rotate=0
				else
					if [ $posY -gt $maxY ]
					then
						xrandr_rotate=inverted
						wacom_rotate=3
					fi
				fi
			fi
		fi
	fi

	echo "STATUS: $xrandr_status $wacom_status"
	echo "TARGET: $xrandr_rotate $wacom_rotate"

	if [ "$xrandr_status" != "$xrandr_rotate" -o "$wacom_status" != "$wacom_rotate" ]
	then
		xrandr_status=$xrandr_rotate
		wacom_status=$wacom_rotate
		xrandr --output LVDS --rotation $xrandr_status
		xsetwacom set stylus Rotate $wacom_status
		echo "ROTATE: $xrandr_status"

		if [ "$xrandr_rotate" = "right" ]
		then
			
			sudo setkeycodes 71 105
			sudo setkeycodes 6d 103
			sudo setkeycodes 6f 106
			sudo setkeycodes 6e 108
		fi

		if [ "$xrandr_rotate" = "left" ]
		then
			sudo setkeycodes 71 106
			sudo setkeycodes 6d 108
			sudo setkeycodes 6f 105
			sudo setkeycodes 6e 103	
		fi

		if [ "$xrandr_rotate" = "normal" ]
		then
			sudo setkeycodes 71 103 
			sudo setkeycodes 6d 106 
			sudo setkeycodes 6f 108 
			sudo setkeycodes 6e 105	
		fi

		if [ "$xrandr_rotate" = "inverted" ]
		then
			sudo setkeycodes 71 108
			sudo setkeycodes 6d 105
			sudo setkeycodes 6f 103
			sudo setkeycodes 6e 106		
		fi
	fi
done
So - jetzt hätte ich das ganze aber gerne etwas eleganter gelöst. Irgendwie kommen mir Arrays in den Kopf wenn ich die setkeycode Sache so sehe und Funktionen würde ich auf gerne einbauen, einfach damit das ganze übersichtlicher wird. Aber fangen wir mal mit den Arrays an. Gibts hier sowas wie ich es von PHP kenne: Ein 2D Array mit dem man z.B. "normal" auf [103, 106, 108, 105] mappen kann. Gibts sowas hier auch? Die Tutorials zu Shell Programmierung, die ich gefunden habe, sind leider etwas mager.

EDIT: Achja, meine Abschalt-Methode gefällt mir auch nicht sonderlich. Geht das nicht schöner?

mfg
serow
Serow ist offline   Mit Zitat antworten
Alt 10.07.08, 21:39   #11 (permalink)
 
Registriert seit: 22.10.05
farhaven Leistung: Z3
Likes: 3
Standard

Auszug aus man bash, Kapitel Arrays:

Zitat:
Bash provides one-dimensional array variables. Any variable may be used as an array; the declare builtin will explicitly declare an array. There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned contiguously. Arrays are indexed using integers and are zero-based.

An array is created automatically if any variable is assigned to using the syntax name[subscript]=value. The subscript is treated as an arithmetic expression that must evaluate to a number greater than or equal to zero. To explicitly declare an array, use declare -a name (see SHELL BUILTIN COMMANDS below). declare -a name[subscript] is also accepted; the subscript is ignored. Attributes may be specified for an array variable using the declare and readonly builtins. Each attribute applies to all members of an array.

Arrays are assigned to using compound assignments of the form name=(value1 ... valuen), where each value is of the form [subscript]=string. Only string is required. If the optional brackets and subscript are supplied, that index is assigned to; otherwise the index of the element assigned is the last index assigned to by the statement plus one. Indexing starts at zero. This syntax is also accepted by the declare builtin. Individual array elements may be assigned to using the name[subscript]=value syntax introduced above.

Any element of an array may be referenced using ${name[subscript]}. The braces are required to avoid conflicts with pathname expansion. If subscript is @ or *, the word expands to all members of name. These subscripts differ only when the word appears within double quotes. If the word is double-quoted, ${name[*]} expands to a single word with the value of each array member separated by the first character of the IFS special variable, and ${name[@]} expands each element of name to a separate word. When there are no array members, ${name[@]} expands to nothing. If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. This is analogous to the expansion of the special parameters * and @ (see Special Parameters above). ${#name[subscript]} expands to the length of ${name[subscript]}. If subscript is * or @, the expansion is the number of elements in the array. Referencing an array variable without a subscript is equivalent to referencing element zero.

[...]
Bash unterstützt also leider nur eindimensionale Arrays. Wenn du allerdings etwas mit dem IFS herumspielst, dann sollte es relativ problemlos möglich sein, mehrere Quasi-Arrays in einem Array zu speichern, und zwar so:

Code:
export IFS="
"

buttons=("105 103 106 108" "106 108 105 103" "103 106 108 105" "108 105 103 106" "71 6d 6f 6e")
Um dann auf die einzelnen "Unter-Arrays" zuzugreifen, könntest du zum Beispiel folgenden Code benutzen
Code:
export IFS=" "

[ "$xrandr_rotate" = "right" ] && orientation = 0
[ "$xrandr_rotate" = "left" ] && orientation = 1
[ "$xrandr_rotate" = "normal" ] && orientation = 2
[ "$xrandr_rotate" = "inverted" ] && orientation = 3

i=0

while [ i -lt 4]; do
 sudo setkeycodes ${buttons[4]}  `echo ${buttons[$orientation] | cut -f $i`
 i=$(($i + 1))
done
ich hab den Code zwar selber nicht getestet, wenn ich keinen allzugrossen Fehler gemacht habe, dann sollte das allerdings mit minimalen Änderungen funktionieren
farhaven ist offline   Mit Zitat antworten
Alt 10.07.08, 23:09   #12 (permalink)
Senior Member
Themenstarter
 
Registriert seit: 26.03.06
Serow Leistung: 8086
Likes: 16
Standard

Ahja danke schön, das klappt zwar so noch nicht ganz aber wenn man dem cut per -d " " den delimiter mitgibts gehts:

Code:
#!/bin/bash

export IFS=" "

############################################################
## CONSTANTS ###############################################
############################################################ 
SLEEP_TIME=1
LAPTOP_MODE_FILE=/etc/tabletmode
MODE_TABLET=tablet
MODE_LAPTOP=laptop
CALIBRATE_FILE=/sys/devices/platform/hdaps/calibrate
RESISTANCY=50
POSITION_FILE=/sys/devices/platform/hdaps/position
XRANDR=("normal" "right" "inverted" "left")
WACOM=("0" "1" "3" "2")
BUTTONS=("103 106 108 105" "105 103 106 108" "108 105 103 106" "106 108 105 103" "71 6d 6f 6e")

############################################################
## VARIABLES ###############################################
############################################################
orientation=-1
next_orientation=-1
calibX=`cut -d , -f 1 < $CALIBRATE_FILE | sed "s/(//"`
calibY=`cut -d , -f 2 < $CALIBRATE_FILE | sed "s/)//"`
minX=$(($calibX-$RESISTANCY))
minY=$(($calibY-$RESISTANCY))
maxX=$(($calibX+$RESISTANCY))
maxY=$(($calibY+$RESISTANCY))	

############################################################
## MAIN LOOP STARTS HERE ###################################
############################################################
while :
do
	sleep $SLEEP_TIME

	laptopMode=`cat $LAPTOP_MODE_FILE`

	if [ "$laptopMode" = "$MODE_LAPTOP" ]
	then
		#echo "Computer is in Laptop Mode"
		laptop_status=$MODE_LAPTOP
		next_orientation=0
	else
		#echo "Computer is in Tablet Mode"	

		if [ "$laptop_status" = "$MODE_LAPTOP" ]
		then
			laptop_status=$MODE_TABLET
		fi
	
		posX=`cut -d , -f 1 < $POSITION_FILE | sed "s/(//"`
		posY=`cut -d , -f 2 < $POSITION_FILE | sed "s/)//"`		
			
		if [ $minX -lt $posX -a $posX -lt $maxX -a $minY -lt $posY -a $posY -lt $maxY ]
		then
			next_orientation=2 #inverted
		else	
			if [ $posY -gt $maxY -a $minX -lt $posX -a $posX -lt $maxX ]
			then
				next_orientation=2 #inverted
			else 
				if [ $posY -lt $minY -a $minX -lt $posX -a $posX -lt $maxX ]
				then
					next_orientation=0 #normal
				else
					if [ $posX -lt $minX -a $minY -lt $posY -a $posY -lt $maxY ]
					then
						next_orientation=3 #left
					else
						if [ $posX -gt $maxX -a $minY -lt $posY -a $posY -lt $maxY ]
						then	
							next_orientation=1 #right
						else
							next_orientation=$orientation
						fi
					fi
				fi
			fi
		fi
	fi

	if [ "$orientation" != "$next_orientation" ]
	then
		orientation=$next_orientation

		echo "Orientation: ${XRANDR[$orientation]}"

		xrandr --output LVDS --rotation ${XRANDR[$orientation]}
		xsetwacom set stylus Rotate ${WACOM[$orientation]}

		i=0
		while [ $i -lt 4 ]
		do
			sudo setkeycodes `echo ${BUTTONS[4]} | cut -d " " -f $(($i + 1))` `echo ${BUTTONS[$orientation]} | cut -d " " -f $(($i + 1))`
			i=$(($i + 1))
		done
	fi
done
Jetzt würde ich noch gerne die if-else-Hölle loswerden ... Gibts da ne schönere Schreibweise?

Die manpage zu bash ist ja krass. Endlos lang und garnicht leicht zu verstehn
Serow ist offline   Mit Zitat antworten
Alt 10.07.08, 23:56   #13 (permalink)
 
Registriert seit: 22.10.05
farhaven Leistung: Z3
Likes: 3
Standard

So wie ich das sehe, kann man diesen If-Sumpf nicht wirklich verkleinern. Was evtl. lesbarer wäre, wäre anstatt
Code:
if foobar
then
snafu
fi
zu schreiben
Code:
if foobar; then
snafu
fi
aber wirklich viel kann man da glaube ich nicht verbessern
farhaven ist offline   Mit Zitat antworten
Antwort
   
- Anzeige -

Werbung ist gerade online    

[HaBo] » Operating Systems » Linux/UNIX » Shell Script Probleme
Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind aus
Pingbacks sind aus
Refbacks sind aus


Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Werte von Shell script in aufrufendes Programm zurückgeben blueflash Linux/UNIX 5 13.08.08 23:27
Linux shell script als Win Anwendung schmidtl_dd Code Kitchen 1 11.02.06 20:17
Shell Iker C. Code Kitchen 1 14.02.04 18:06
Shell in VB TheEvilOne Code Kitchen 11 09.12.02 09:57
wie erstelle ich eine perl-shell in einem cgi-script honkman (Web-) Design und webbasierte Sprachen 3 15.10.02 11:49


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61