small hackish bash script...

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
Carl
Level 5
Level 5
Posts: 701
Joined: Wed Apr 15, 2009 5:20 pm
Location: Isle of Wight, UK

small hackish bash script...

Post by Carl »

I'm trying to create a small script which is going to ask me whether or not I want to disable compiz before loading a game however so far I can get it to turn off compiz and not load the game (i'd like it to turn off compiz and then load the game..) or I can get it to not turn off compiz and then load the game :? bearing in mind I've basically hacked this together from bit's and bobs on Google and I have no real knowledge of bash or zenity :roll:

Code: Select all

#!/bin/bash

zenity --question --text "Would You like to disable Compiz before continuing?"
if [[ $? == 0 ]] ; then
   metacity --replace 
   exec SDL_VIDEO_X11_DGAMOUSE=0 teeworlds
else
   exec SDL_VIDEO_X11_DGAMOUSE=0 teeworlds
fi
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: small hackish bash script...

Post by xenopeek »

Some small changes, this should work and re-enable Compiz after running the game.

Code: Select all

#!/bin/bash

zenity --question --text "Would You like to disable Compiz before continuing?"
if [[ $? == 0 ]] ; then
   metacity --replace &
   sleep 1
   exec SDL_VIDEO_X11_DGAMOUSE=0 teeworlds
   compiz --replace &
else
   exec SDL_VIDEO_X11_DGAMOUSE=0 teeworlds
fi
Image
User avatar
Carl
Level 5
Level 5
Posts: 701
Joined: Wed Apr 15, 2009 5:20 pm
Location: Isle of Wight, UK

Re: small hackish bash script...

Post by Carl »

xenopeek wrote:Some small changes, this should work and re-enable Compiz after running the game.

Code: Select all

#!/bin/bash

zenity --question --text "Would You like to disable Compiz before continuing?"
if [[ $? == 0 ]] ; then
   metacity --replace &
   sleep 1
   exec SDL_VIDEO_X11_DGAMOUSE=0 teeworlds
   compiz --replace &
else
   exec SDL_VIDEO_X11_DGAMOUSE=0 teeworlds
fi
Error:

Code: Select all

./test: line 7: exec: SDL_VIDEO_X11_DGAMOUSE=0: not found
that partially works but only if I remove the "SDL_VIDEO_X11_DGAMOUSE=0" part from the script and also it doesn't re-enable compiz afterwards

Thanks for trying :D
User avatar
Carl
Level 5
Level 5
Posts: 701
Joined: Wed Apr 15, 2009 5:20 pm
Location: Isle of Wight, UK

Re: small hackish bash script...

Post by Carl »

But this works perfectly :D Thanks for your help! although it would be good to know why removing "exec" and using parentheses works instead :?:

Code: Select all

#!/bin/bash

zenity --question --text "Would You like to disable Compiz before continuing?"
if [[ $? == 0 ]] ; then
   metacity --replace &
   sleep 1
   (SDL_VIDEO_X11_DGAMOUSE=0 teeworlds)
   compiz --replace &
else
   exec SDL_VIDEO_X11_DGAMOUSE=0 teeworlds
fi
Locked

Return to “Scripts & Bash”