Register
It is currently Mon Sep 01, 2014 12:33 pm

I need some help cleaning this up.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue Nov 19, 2013 10:15 am   

Joined: Tue Nov 19, 2013 10:07 am
Posts: 1
So I'm very new to using bash scripts. I am working on a text based application launcher. Im sure there is an easier way to write out allof these "ifs". When I look at it it just feels messy and ridiculously long for what it does. Is there an easier/cleaner way?


#!/bin/bash

echo "--------------------------------------------------"
echo "$(date)"
echo "--------------------------------------------------"
echo "What would you like to use?"
echo ""
echo "System:"
echo "system_monitor, network_monitor, update, logout"
echo ""
echo "Local actions"
echo "file(_text), music, office"
echo ""
echo "Games:"
echo "minecraft(_server)"
echo ""
echo "Internet:"
echo "chrome, facebook, youtube"
echo ""
echo "Settings:"
echo "launcher_settings, comp_settings"
read answer
if [ $answer = chrome ]
then chromium-browser
elif [ $answer = facebook ]
then chromium-browser http://www.facebook.com
elif [ $answer = youtube ]
then chromium-browser http://www.youtube.com
elif [ $answer = file ]
then thunar
elif [ $answer = file_text ]
then ranger
elif [ $answer = system_monitor ]
then htop
elif [ $answer = network_monitor ]
then sudo iftop -p -i wlan0
elif [ $answer = update ]
then sudo apt-get update && sudo apt-get upgrade
elif [ $answer = logout ]
then xfce4-session-logout
elif [ $answer = music ]
then cmus
elif [ $answer = launcher_settings ]
then nano ~/bin/jarvis.sh
elif [ $answer = comp_settings ]
then xfce4-settings-manager
elif [ $answer = office ]
then libreoffice
elif [ $answer = minecraft ]
then java -jar ~/Games/Minecraft/Minecraft.jar
elif [ $answer = minecraft_server ]
then java -jar ~/Games/Minecraft_Server/minecraft_server.1.7.2.jar nogui
else $answer
fi


Top
 Profile  
 PostPosted: Wed Nov 20, 2013 6:21 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
hi,

Code:
case $answer in
chrome) chrome-browser ;;
facebook) chrome-browser http://facebook.com ;;
# and so on
esac


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP