[SLE] Bat files in Linux

From: Steve Reynolds (reynolds_at_fastmail.com.au)
Date: 04/29/04

  • Next message: expatriate: "Re: [SLE] DLT Tape Library instalation"
    To: suse-linux-e@suse.com
    Date: Thu, 29 Apr 2004 23:21:40 +0930
    
    

    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>

    -- 
    Check the headers for your unsubscription address
    For additional commands send e-mail to suse-linux-e-help@suse.com
    Also check the archives at http://lists.suse.com
    Please read the FAQs: suse-linux-e-faq@suse.com
    

  • Next message: expatriate: "Re: [SLE] DLT Tape Library instalation"

    Relevant Pages

    • Robocopy fails sporadically
      ... if errorlevel 16 echo FATAL ERROR on BACKUP of %~n0's DATA>> ... if errorlevel 8 echo FAILED COPIES on BACKUP of %~n0's DATA>> ...
      (microsoft.public.windows.server.general)
    • Re: dos batch programmer help!!
      ... REM Set up your two serial numbers here and ensure dir C:\TEMP\ exists ... if errorlevel 1 goto otherdisk ... echo Wrong diskin H: -- swap it to allow backup to continue! ...
      (comp.os.msdos.programmer)
    • Re: dos batch programmer help!!
      ... echo Please install the backup tape ... if exist testtape.ok goto goodtape ... echo ERROR ERROR ERROR ...
      (comp.os.msdos.programmer)
    • Re: dos batch programmer help!!
      ... REM Set up your two serial numbers here and ensure dir C:\TEMP\ exists ... if errorlevel 1 goto otherdisk ... echo Wrong diskin H: -- swap it to allow backup to continue! ...
      (comp.os.msdos.programmer)
    • Re: Is there something like "Perl FindBin" in DOS?
      ... echo Path is "%PATHNAME%" ... goto end ... > That is a way to inform my executing .bat file where it is itself inside the ...
      (comp.os.msdos.misc)