Command Script

Forum rules
Before you post please read this

Command Script

Postby lpmorgan1 on Tue Dec 18, 2012 8:37 am

I can type command line instructions in the terminal window, but I want to do like I used to do in dos.

Instead of memorizing complex commands, I would create a BAT file, sometimes with a string of commands.
Sometimes it was just one command with complex options.

I would then just run the BAT file.

I am certain there is a way to do this in Linux Mint.

Would somebody share it?

Larry of the Traveling Morgans
-----
Larry of the Traveling Morgans
http://travelingmorgans.com
lpmorgan1
Level 1
Level 1
 
Posts: 3
Joined: Tue Dec 18, 2012 8:31 am

Linux Mint is funded by ads and donations.
 

Re: Command Script

Postby mank_in on Tue Dec 18, 2012 8:40 am

Image
Sorry for my bad English , I am Indonesian.
User avatar
mank_in
Level 6
Level 6
 
Posts: 1346
Joined: Wed Nov 16, 2011 2:29 pm
Location: Bali

Re: Command Script

Postby mauler5858 on Tue Dec 18, 2012 9:38 am

You can use bash shell scripting in order to accomplish most of these things.

The basis of a bash script starts like this:

Code: Select all
#!/bin/bash

YOUR CODE HERE


You then need to mark the file executable and then it can be run from the command line via:

Code: Select all
. YOURSCRIPTNAME


I would, however, spend some time learning the terminal and its commands. it will pay off in the long run.
mauler5858
Level 1
Level 1
 
Posts: 3
Joined: Wed May 30, 2012 8:30 am

Re: Command Script

Postby BrianD on Tue Dec 18, 2012 10:06 am

actually, you can write in Bash (or any other shell) script, perl, awk, python, etc, etc...

instead of naming your script file with a ".BAT" extension (like you did in DOS/Windows), in Linux/Unix you just start the script with a comment that signifies the appropriate interpreter for the script that follows, i.e.:

#!/bin/bash ...or
#!/usr/bin/perl ...or
#!/usr/bin/python ...etc

...so then, an example bash script:

Code: Select all
#!/bin/bash
# this line is a comment, like any other line beginning with a '#' symbol
#
# ...these, too!
ls -hort ~            # ...and, any character after the '#' on any given line is ignored by the interpreter, so you can 'document' your scripts
                         # this line, for instance, does a directory listing of the currently logged-in user's home directory, in human readable, long form, sorted in reverse chronological order
echo "all done!"  # this will print 'all done!' on standard out at the conclusion of the script

# fini


when the editing is complete, just add the 'executable' bit to the script file you created by running "chmod +x <script_file_name>"
-- where <script_file_name> is replaced with the actual name of the script file you've created

...once you've finished your script, and you wish to make it available to others (or just have it handy for yourself), you can place it in /usr/local/bin (which is on the $PATH), and you can then invoke it by name from anywhere on the system.
need I say more??
BrianD
Level 4
Level 4
 
Posts: 306
Joined: Fri Feb 12, 2010 12:22 am
Location: Tallahassee, Florida, USA

Re: Command Script

Postby BrianD on Tue Dec 18, 2012 10:23 am

...additionally, there are several references on bash scripting, perl scripting, and python scripting available on the internet, as well as several books that will serve as learning material and/or reference. I would heartily recommend any title published by O'Reilly & Associates (you can find them at your local bookstore, on Amazon, or directly from www.oreilly.com (and, if you belong to a Linux User Group, you can take a discount when you purchase online, directly).

some examples (also books that I actually own and have read):
Learning the bash Shell http://shop.oreilly.com/product/9780596009656.do
Learning Perl http://shop.oreilly.com/product/0636920018452.do
Think Python http://shop.oreilly.com/product/0636920025696.do
need I say more??
BrianD
Level 4
Level 4
 
Posts: 306
Joined: Fri Feb 12, 2010 12:22 am
Location: Tallahassee, Florida, USA

Re: Command Script

Postby xenopeek on Tue Dec 18, 2012 10:35 am

Bash is the easiest scripting language to get started with, as it accepts the same commands as you have been using on the terminal. A very good introduction is Introduction to the Command Line. See the link on that page, you can also read if for free online or download it.
User avatar
xenopeek
Level 21
Level 21
 
Posts: 15051
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Command Script

Postby lpmorgan1 on Tue Dec 18, 2012 11:32 pm

Regarding:
I would, however, spend some time learning the terminal and its commands. it will pay off in the long run.

Sorry, I am good at figuring things out. Never was good at memorizing. Since I turned 65 it has been worse. Still enjoy learning new things though.
It would be NICE to have a good memory. I just don't.
-----
Larry of the Traveling Morgans
http://travelingmorgans.com
lpmorgan1
Level 1
Level 1
 
Posts: 3
Joined: Tue Dec 18, 2012 8:31 am

Linux Mint is funded by ads and donations.
 

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 2 guests