Translate source code.
Translating from one batch file system to another can be interesting. As a former admin, I had to do that with Novell scripts and convert them to MSWindows batch files when we were changing systems. Someone wrote a batch file for emulate a menu to launch the browser to go to different sites that could of been a bit more precise for dos, but I decided to translate it to bash.
Dos:
Dos:
@echo off color 0e Title Website Starter (by Prof. Pickle) :Menu cls echo --------------------------------------------------------------------- echo This is the Website starter echo. echo Select the number of the website you wish to select echo Or press E to exit. echo --------------------------------------------------------------------- echo. echo. echo 1. facebook echo 2. youtube echo 3. google echo 4. redtube echo 5. other set /p web= If %web% EQU 1 start www.facebook.com If %web% EQU 1 goto Menu If %web% EQU 2 start www.youtube.com If %web% EQU 2 goto Menu If %web% EQU 3 start www.google.com If %web% EQU 3 goto Menu If %web% EQU 4 start www.redtube.com If %web% EQU 4 goto Menu If %web% EQU 5 goto other If %ERRORLEVEL% NEQ 0 goto ERROR If %web% EQU E goto exit If %web% EQU e goto exit goto please :other cls echo You have chosen other echo. echo Type the web address of the website (www.website.com) set /p otherweb= start %otherweb% If %ERRORLEVEL% NEQ 0 goto ERROR :exit cls echo Goodbye! pause > nul exit :ERROR cls echo Sorry, an error has occurred. echo. echo If you were using the "other website" function you may have echo typed it incorrectly. echo. echo Press any key to go back to menu pause > nul goto Menu :please cls echo Please press a number from 1-5 echo. pause goto Menu
Sure the author worked really hard on it. then I thought how would I do a quick equivalent using bash. To be fair his batch code could of been improved with a while loop. You can replace firefox for the browser of your choice. This is what I came up with:
Bash:
#!/bin/bash # # Script to run firefox and load a specific site. # while : do clear echo "************************" echo "* My website loader *" echo "************************" echo "* [1] Facebook *" echo "* [2] Google *" echo "* [3] Twitter *" echo "* [4] Youtube *" echo "* [5] Some other site *" echo "* *" echo "* [0] Exit/Stop *" echo "************************" echo -n "Enter your menu choice [1-5, or 0]: " read yourch case $yourch in 1) firefox http://www.facebook.com & ;; 2) firefox http://www.google.com & ;; 3) firefox http://www.twitter.com & ;; 4) firefox http://www.youtube.com & ;; 5) echo ; read -p "Enter website: " ws ; firefox $ws & ;; 0) exit 0;; *) echo "Oopps!!! Please select choice 1,2,3, 4 or 5"; echo "Press Enter to continue. . ." ; read ;; esac done
Which generates a screen something like this.
************************ * My website loader * ************************ * [1] Facebook * * [2] Google * * [3] Twitter * * [4] Youtube * * [5] Some other site * * * * [0] Exit/Stop * ************************ Enter your menu choice [1-5, or 0]:
Comments
Post a Comment