What is shell scripting?

Recommended Answers

All 3 Replies

When talking about "programming" people tend to think that all code is a "program", but this just isn't true. Languages like VB, and C/C++, require that you first take the code that you write, and convert it to machine code (compile). After that (often done in the same step) you then "link" your code together into a Program. Linking has to do with putting together required external code (libraries) that are required by your program. Anyway, getting off topic, "Programming" is compiled into machine code.

Scripting is a different animal. Scripting doesn't require (from a top level view, anyways) that the code you write be compiled. Now, obviously before any code can run on a system, it must first be converted, but the compilation and linking isn't done by the programmer in a script. You have a program (typically called an Interpreter) that runs the lines of the script, and essentially compiles them on the fly. So, as the script writer, all you have to do is make changes to your script, and run it. The only drawbacks to this, is that your code is always available for view by anyone (that's actually a plus if you ask me), and it's slower when running. Compiled programs are typically fast, and scripts are usually slow. I wouldn't write something like a video game (even if there are libraries for it) in a scripting language. I might do something not time critical in one though. That's the general difference between programming and scripting, and I guess helps to answer what a "script" is.

In *nix, you have a wide variety of interfaces, because the idea is that the user is in control of their environment, unlike an OS such as windows, where you pretty much have to deal with the same interfaces. The command line in windows/DOS will never change...the syntax, etc. In *nix you can choose your own interface for the command line...this interface is called a shell. The most popular (by far) interface is Bash (The Bourne Again Shell). Most (if not all) operating systems provide a way to "batch commands" into a single file. So that when you run this simple script, it does a sequence of command line commands, that are typically repetitious and a pain to type over and over. Don't underestimate its power however, thinking that it is stuck just with batched command line commands.... it has the power of if statements, and loops, for conditional branching and recursive behavior. Shell scripts are a very powerful tool, that are often overlooked.

thanks for the quick and in-depth reply, What kind of things have people have managed to do with shell scripting?

also, i know this might not be the right place to ask, but how do people become a moderator of the forums?

That's a list there. People will be able to post answers to that question for ages..... a couple common uses of Shell Scripts have been things such as log file rotations (programs can generate files that detail what it did, or what occured, called a log, they get too big, and a company wants them archived, so they build a shell script to automatically copy the log, (or group of logs) compress them, and back them up, then clear/remove the originals). There have been shell scripts to download youtube video's to your hard-drive... heck, a lot of startup scripts (startx... a big one) is a shell script. Shell scripts that monitor zombie processes...etc, etc. It's a big list.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.