LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Batch File Equivalent (https://www.linuxquestions.org/questions/programming-9/batch-file-equivalent-182184/)

johnsmith1169 05-16-2004 04:59 PM

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.

slakmagik 05-16-2004 05:16 PM

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.

johnsmith1169 05-16-2004 05:22 PM

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

slakmagik 05-16-2004 05:30 PM

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.

Hko 05-16-2004 07:10 PM

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


All times are GMT -5. The time now is 04:13 PM.