Mailinglist Archive: opensuse (2271 mails)

< Previous Next >
Bat files in Linux
  • From: Steve Reynolds <reynolds@xxxxxxxxxxxxxxx>
  • Date: Thu, 29 Apr 2004 23:21:40 +0930
  • Message-id: <200404292321.40341.reynolds@xxxxxxxxxxxxxxx>
I have a few commands that I would like to run at the command prompt.

In Windows I do this with a bat file that looks like the sample below. How do
I do a similar thing with Linux?

For those not familiar with windows bat files the snippet below presents the
user with a menu at the command prompt.

In windows I have a shortcut to a text file called backup.bat, when I double
click that shortcut I launch a DOS window with the menu below already loaded
for the user. I would like to do a similar thing with Linux.

<begin bat file snippet>

@ECHO OFF
CLS
:LOOP
ECHO Backup Menu
ECHO ===========
ECHO A. Flash Drive Backup J:
ECHO B. Main Backup to CD
ECHO C. Main Backup to F Drive
REM ECHO D. Archive Backup
ECHO E. Allofmp3 Backup to CD
ECHO F. Flash Drive Backup I:
REM ECHO G. REVERSE Flash Drive Backup From Linux:
ECHO H. Photos Backup to iPod
ECHO Q. Quit
:: SET /P prompts for input and sets the variable
:: to whatever the user types
SET Choice=
SET /P Choice=Type the letter and press Enter:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
:: /I makes the IF comparison case-insensitive
IF /I '%Choice%'=='A' GOTO ItemA
IF /I '%Choice%'=='B' GOTO ItemB
IF /I '%Choice%'=='C' GOTO ItemC
IF /I '%Choice%'=='D' GOTO ItemD
IF /I '%Choice%'=='E' GOTO ItemE
IF /I '%Choice%'=='F' GOTO ItemF
IF /I '%Choice%'=='G' GOTO ItemG
IF /I '%Choice%'=='H' GOTO ItemH
IF /I '%Choice%'=='Q' GOTO End
ECHO "%Choice%" is not valid. Please try again.
ECHO.
GOTO Loop
:ItemA
<snip>

<end bat file snippet>


< Previous Next >