On 29 Apr, Steve Reynolds wrote:
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>
Steve, If this kind of customization is what you expect from your computer, you have come to the right place. With patience, GNU/Linux will likely become your happy home. This said, a little reading and experimentation will yield far greater results here than in a MS Windows environment. While .bat files provide a handy method through which to create quick utilities, particularly for configuration and file management purposes, they are limited in their ability to interact with other programs that virtually require a GUI interface. Not so in an Unix environment, which is essentially all about text files calling on one another - with no need for GUI startups. In fact, most everything runs better behind the scenes. Pontification aside, here's what I recommend. Get some instructional material on Shell, Perl and TK. Knowledge in these areas will allow you to write just about any command line app you require. They're rather intuitive to my mind, and you should be able to learn them quickly. Coming from a windows environment, I think you will find TK of particular use, as it facilitates a series of apps that will help you learn the differences between Windows and Unix methodologies. Also, I strongly urge you to read your existing Shell scripts and configuration files religiously. Even if you don't quite understand them in the beginning, follow their system calls and library loading, etc., as much as you can. Again, Unix/Linux functions through a series of interlaced files (largely text). So if you master the art of reading these files and start to write your own, you will have total control ;) - which is really what we mean by FREE software. I realize this might sound like preaching, but I wish someone had properly explained the need for this information when I started running this very distro some five years ago. I can't tell you how much I struggled trying to make early Yast configure everything for me (what a mangled mess I would weave in those early days). Welcome and cheers!! Regards, -- John Lalla Santa Barbara, CA .~. _ /v\ -o) no gates... /( )\ /\\ running GNU/Linux no windows! ^^^^^ _\_v free at last! "Our capacity for understanding is inversely proportional to how much we think we know. The more I know, the more I know I don't know . . . "