LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-16-2004, 04:59 PM   #1
johnsmith1169
LQ Newbie
 
Registered: May 2004
Posts: 2

Rep: Reputation: 0
Batch File Equivalent


I'm just starting to get used to linux. I've been using slackware for 2 weeks now. I do some programming in vB, but when I just need to write something really simple, I will write a batch file. So my question is can I write a program to run in the shell script without having to know C/C ++? Thanks in advance.
 
Old 05-16-2004, 05:16 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
I don't understand the question. Bash is a shell (as are ksh, tcsh, and zsh) and a programming language of sorts. Shell scripts are like immeasurably more powerful batch files, yes. Go for it. Check out bash tutorials at the TLDP and various other things on the web and check out the bash man page (or shell of your choice).

-- Occurs to me to add: if you know any Linux commands at all, put a few in a text file that begins with

#!/bin/bash

The shebang (#!) declares it's a script to be interpreted by (in this case) bash. (You can also do #!/bin/less or #!/bin/awk -f or whatever.)

Then issue 'chmod 700 filename' and do

./filename

Voila. Script. (If the current directory is in your path or you save the file to a directory that is on your path you can just issue 'filename' without the './' You can also chmod it 7nn where n's anything you want - point is to make it executable for you at the very least.)

Then look into flow control - 'for...do...done', 'if...then...fi' and so on. Then go from there.

Last edited by slakmagik; 05-16-2004 at 05:22 PM.
 
Old 05-16-2004, 05:22 PM   #3
johnsmith1169
LQ Newbie
 
Registered: May 2004
Posts: 2

Original Poster
Rep: Reputation: 0
I think you understood what I meant. Sorry if it wasn't clear.

What I mean is in windows you can open notepad, write out some DOS commands, save it as a .bat and run it. I'll go research Bash and shell scripts. Thanks.

EDIT: Thanks for adding that extra info. That's exactly what i was trying to find out. What extension do I give to my script? Like how in win, it's .bat

Last edited by johnsmith1169; 05-16-2004 at 05:25 PM.
 
Old 05-16-2004, 05:30 PM   #4
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
No, it was clear. Reading over it, I'm not sure what I didn't get myself. Sounded kind of like you were answering your own question, I guess - batch file=shell script. But, yeah, where to begin with them.

And welcome to Linux and LQ.

-- Oops. Missed the last edit. I don't give them any extension but convention is '.sh' if you do give them an extension. The executable bit is the key and the extension is arbitrary - different from DOS.

Last edited by slakmagik; 05-16-2004 at 05:32 PM.
 
Old 05-16-2004, 07:10 PM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
EDIT: Thanks for adding that extra info. That's exactly what i was trying to find out. What extension do I give to my script? Like how in win, it's .bat
In Windows/DOS the system recognizes a file to be executable by its "extension", e.g: .cmd, .exe, .pif, .scr.....

In Linux "executabitlity" of a file is a filesystem right. "Extensions" dont have meaning in Linux. (The only way a GNU/Linux system uses the pattern of file names is with hidden files: they start with a dot).

To give every user on the system the execute-right on a file, enter this on console/terminal:

chmod +x filename
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sftp using a batch file JeRrYmAn Linux - Security 2 05-05-2006 10:15 AM
batch file for chmod's? teodavinci Linux - Newbie 3 08-13-2004 03:04 PM
batch file for chmod's? teodavinci Linux - Networking 1 08-13-2004 02:39 PM
DOS batch equivalent PyroBoy101 Linux - Newbie 5 01-28-2004 08:08 PM
writing a batch file ???? Micro Linux - General 3 01-09-2003 11:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:32 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration