LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-11-2003, 12:12 PM   #1
srgusa
LQ Newbie
 
Registered: Jun 2003
Distribution: Mandrake 9.1
Posts: 6

Rep: Reputation: 0
Total Newb question..


Hi,

Sorry for the complete newbie question but I'm having trouble finding a coherent answer to this. I really just need a simple answer to this if that's possible.

Is there an equivalent in Unix/Linux to a DOS or Windows batch file (.bat, .cmd)?

I'm just trying to find out what type of file I need to create with maybe a few commands in it, that I can run from the command line without using Perl or SH or something.

In essence, I just want to create a file that will automate a series of command lines.

Thanks much!
 
Old 06-11-2003, 12:14 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,396

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
linux LIVES on script files, which can do SO SO SO SO SOmuch more than a pitiful batch file ever could. have a look at the bash scripting howto at tldp.org or skim though the rute guide in my signature.

I'm sure you'll see how funny that question seems to someone who knows about scripting!
 
Old 06-11-2003, 12:16 PM   #3
roesingape
LQ Newbie
 
Registered: May 2003
Location: hellinnati
Posts: 16

Rep: Reputation: 0
that's what SH is for...just make a shell script... download a simple one and customize it, or, write the commands all on one line in bash then whenever you want to do them just push arrow up until it appears. 9 times out of ten there's already something written to do what you want...hope this helps...I'm a newbie too..
 
Old 06-11-2003, 12:25 PM   #4
srgusa
LQ Newbie
 
Registered: Jun 2003
Distribution: Mandrake 9.1
Posts: 6

Original Poster
Rep: Reputation: 0
Yep I was able to figure out that if i put the lines i want into a text file, name it whatever with no extension, the do SH <filename> at the prompt that it runs with no problem.

The problem I have is, How do I run a file like that without typing SH first? I just want to RUN the file...ie. type the filename and thats it, no SH or anything. Is that possible?
 
Old 06-11-2003, 12:53 PM   #5
MArgRes
Member
 
Registered: Jun 2003
Distribution: Fedora Core 2
Posts: 37

Rep: Reputation: 15
Yes, you can. First you (obviously) have to have the execute bit set on the file. (Do an ls -l to find out.) If it isn't, you'll have to do a chmod to set it. If it is set, you have to put the file in your 'path' for you to be able to execute it directly. To find out your path, type 'echo $PATH'. It will show you a list of directories where you could put it to have the shell look there first. You can add a directory to your path by editing your .bash_profile file and putting something like:

PATH=PATH:$HOME/<your-dir>
export PATH

and then putting the file in the <your-dir> directory. As a side note, instead of typeing 'sh filename' to execute it, you can also type '. filename' (just a dot and then the file), and it does the same thing (as long as you're in the same dir as the file).
 
Old 06-11-2003, 01:01 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,396

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
Quote:
PATH=PATH:$HOME/<your-dir>
export PATH
this is not really advisable. your standard path should not be changed unless this is unaviodable.

if you have a script file not on your path then you need to prefix it with the relative or absolute path. e.g ./script in your current directory.

the file does *not* need to be in your path to execute it at all, all that is required is that it is actaully set executable, by running "chmod +x scriptname"
 
Old 06-11-2003, 01:19 PM   #7
srgusa
LQ Newbie
 
Registered: Jun 2003
Distribution: Mandrake 9.1
Posts: 6

Original Poster
Rep: Reputation: 0
Wow you all are great. Thanks so much for the quick and thorough responses.

Unfortunately, I still see nothing that tells me how to RUN the file without typing anything but the file name.

ie. the script is called JUNK

I want to type:

JUNK

and have it run. Not ./JUNK or SH JUNK or .JUNK but just plain ol' JUNK.

Can I do that?
 
Old 06-11-2003, 01:23 PM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,396

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
it is possible by changing the path, yes. but you shouldn't not *WANT* to do that. it is not the way things work. executable files are kept in /bin directories on your path somewhere. It may seem strange to suggest this, but you should do things properly, and call it in a way that may seem annoying to you, as that is the way to do it. the script file, when ready and completed would typically be put in a suitabel location.
 
Old 06-12-2003, 06:53 AM   #9
chakkerz
Member
 
Registered: Dec 2002
Location: Brisbane, Australia
Distribution: RedHat (RHEL, FC, CentOS), openSuSE, Mac OS X
Posts: 653

Rep: Reputation: 32
you need to change the permissions on the file to make it executable, so change directory to where JUNK is located, then run
chmod a+x JUNK

to then subsequently run the file do a:
./JUNK when you are in the directory where JUNK is located

as for disliking ./JUNK
type ./J and hit TAB and it will complete the filename ... four keystorkes, just like typing JUNK
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP Drivers total NEWB question Stoned_Elf Linux - Hardware 2 11-12-2005 09:46 AM
Total newb question R0551 Linux - Newbie 1 06-25-2004 11:58 AM
total newb question..you all hate me already y0bailey Linux - Software 17 12-29-2003 03:47 PM
need Help with everything total newb EyeSeven Linux - Newbie 3 10-15-2003 01:14 AM
Total newb question nerocon Linux - Newbie 3 08-10-2002 01:51 AM


All times are GMT -5. The time now is 12:34 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration