Discover and share the best of the web!
Learn more about Digg by taking the tour.
Linux Shell Scripting Tutorial
freeos.com — This tutorial is designed for beginners who wish to learn the basics of shell scripting/programming plus introduction to power tools such as awk, sed, etc. It is not help or manual for the shell.
- 1290 diggs
- digg it
- schestowitz, on 10/12/2007, -0/+11There's no better way to teaching _computing_, rather than vendor-specific GUI's, than the command-line. People get the notion of a process, of input and output, and the way the different components of the PC interacts. This helps troubleshooting. I can recall the days of DOS when people were encouraged to communicate with computers in a level that inspired some thinking and gave the user great 'expressiveness'. Those days may return to the mainstream, in the form of Monad.
- RedLion, on 10/12/2007, -12/+7"Those days may return to the mainstream, in the form of Monad."
Will this mean that the old "C:/DOS, C:/DOS/RUN, RUN/DOS/RUN!" joke will be replaced with "C:/MONAD, C:/MONAD/RUN, RUN/MONAD/RUN!"? If that will ever happen, please, remember to KILL ME! - Invid, on 10/12/2007, -0/+10That was a great joke, even if your syntax sucks.
- eatApeach993, on 10/12/2007, -0/+7scripting is a wonderful thing. However, there are many more powerful tools, such as perl, which combine shell scripting/awk/etc... that make complicated scripts so much simpler.
- nayr, on 10/12/2007, -0/+1I might point out; It's also for all the BSDs and Mac OS X.
- RedLion, on 10/12/2007, -12/+7"Those days may return to the mainstream, in the form of Monad."
- unlimitedorb, on 10/12/2007, -1/+5This is like a breath of fresh air...
I only wish there was a pdf form of it readily available. I'm experiencing a bookmark-overflow =) - bariswheel, on 10/12/2007, -1/+9Is this actually good or are people digging it because of the title
- dwwatk01, on 10/12/2007, -0/+5I think it would be a bit daunting to someone with no *nix experience whatsoever, but it is pretty in-depth and example-rich. A definite bookmark for me.
- Archon810, on 10/12/2007, -7/+2I really don't see why Linux specifically is mentioned in the title, because the scripting is done inside a shell, using the shell scripting language. Why not say *BSD Scripting Tutorial or *nix Scripting Tutorial?
Linux = will be dugg, *BSD = maybe will be dugg, *nix = probably won't be dugg. - bg2500, on 10/12/2007, -0/+3I am familiar with shell scripting, however, I don't do it often enough to be really proficient. This fills in a lot of blanks and will be something I refer back to when I get hung up on something.
- BlackAdderIII, on 10/12/2007, -0/+1It's pretty basic, but seems to cover ground quite well.
For draft 1 it's OK, but I get the feeling that with the standard of English used, it'd be a complete nightmare for a real beginner to learn from it.
If anyone else has the time, someone should offer to proof-read it for the guy.
- hackwrench, on 10/12/2007, -4/+3These shell scripts have no extension. How does the system know it is a shell script and not a binary. Also how does the system treat the executable bit set/cleared on data files?
Then there's the shell scripts that have
#!/bin/sh
or something similar. How does that work? There seem to be some examples that have that sort of line at the beginning and some that don't. What's the difference?- Wireddd, on 10/12/2007, -0/+8you can execute a shell script several ways, "sh /home/youuser/somescript"
or you can:
chmod 700 /home/youruser/somescript
/home/youruser/somscript
if you do it the last way, it will look for #!/bin/blah at the begining of the file and then use that to process the script - skywake, on 10/12/2007, -3/+1I can't call myself an expert on scripts... I really hate scripts personally
but I can tell you now that basing the type of execution based on file extension should never be done
infact... you should be able to take a "script.sh" or similar and name it "fish.jpg" and still run it
file extensions should be "guides" for the user... not law
as for stuff like "#!/bin/sh" at the top
that tells the terminal where to look when executing the script
I assume when it doesn't have it it would you a default
(presumably bash unless the user specifies otherwise) - Werrismys, on 10/12/2007, -0/+0When you try to run a file with the execute bit set, the shell checks the first 2 bytes (magic). If they are '#!', it is assumed the rest of the line tells what to run this script with.
- hackwrench, on 10/12/2007, -0/+1How else would you keep straight what kind of file is what except for the extension?
Also is it the shell that does the first pass of scanning of #! or does it happen at a lower level? Is there an API call to be used by multiple applications that accepts a file with the executable bit set and scans it for the #!, or is it up to each shell to process it themselves?
- Wireddd, on 10/12/2007, -0/+8you can execute a shell script several ways, "sh /home/youuser/somescript"
- ropers, on 10/12/2007, -1/+12Shouldn't someone who's trying to precisely explain the likes of sed, grep and awk in English have a precise command of... English?
- JGailor, on 10/12/2007, -1/+4Almost hate to agree, but the grammar in that article made my head hurt. It may be a phenomenal article on shell scripting, but I'd prefer to not have to wade through the constant corrections that my brain will start spewing:
less article | yacc | brain
- JGailor, on 10/12/2007, -1/+4Almost hate to agree, but the grammar in that article made my head hurt. It may be a phenomenal article on shell scripting, but I'd prefer to not have to wade through the constant corrections that my brain will start spewing:
- kunduZ, on 10/12/2007, -0/+1
scripts are text files, that must be interpreted when run, if you have a shell script, you will either have to run it as "sh myscript" or with "myscript" but the first line of the file must be #!/bin/bash to tell the terminal what program to use to execute the script.
Similarly , if you have python script, you can run it with "python myscript" or with just "myscript" but the first line of the script must be "#!/bin/python" to tell the terminal what program to use to execute the script. file extensions are there to easily say what script is it are not necessary.- kunduZ, on 10/12/2007, -0/+1..i think when you try to run a text file without specifying what program to use( like python myprogram ), the terminal will read the first line of the file to see what program it should use to execute it(it will be something like "#!/usr/bin/env python" for python scripts or "#!/bin/bash" for shell scripts
- triplep, on 10/12/2007, -0/+6The Linux Documentation Project has better resources for this kind of thing:
Beginner BASH:
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
Advanced BASH Scripting Guide:
http://tldp.org/LDP/abs/html/
I killed a tree and printed the advanced guide quite some time ago, it is an excellent resource.
- supdegrave, on 10/12/2007, -0/+0if you can get past the broken english, it looks pretty solid. i scanned the TOC, and it covers a lot of ground. based on my quick look, i suspect that many of the pages contain only a few lines or paragraphs of content, which can be a bit annoying at times.
edit: i see that several others have made similar comments in the time i was drafting my reply. oh well. - statikuz, on 10/12/2007, -0/+3"In 1991, Linus Torvalds studding Unix at the University, where he used special educational experimental purpose operating system called Minix."
Another (perhaps better) shell scripting tutorial can be found at: http://developer.apple.com/documentation/OpenSource/Conceptual/ShellScripting/index.html- klepto, on 10/12/2007, -0/+1That indeed is a better tutorial, thanks statikuz
- utcursch, on 10/12/2007, -0/+2This version was last updated in 2002:
View->Source:
|| Jay Laxmi Mata Dee ||
Last Updates : Thu., April- 11, 2002 06:18:30 PM (IST)
Instead, go to the tutorial at author's site:
http://www.cyberciti.biz/nixcraft/linux/docs/uniqlinuxfeatures/lsst/
View->Source:
|| Om Ga Ganepate Namha ||
|| Jay Laxmi Mata Dee ||
Last Updates : Fri., Sept- 16, 2006 5:18:13 AM IST
PDF version:
http://www.elib.hbi.ir/computer/OS/pdf/(ebook)%20Linux%20Shell%20Scripting%20Tutorial.pdf- JSPMatrix, on 10/12/2007, -0/+0The cyberciti link was dugg about 10 months ago...
- johnnyrotten, on 10/12/2007, -0/+0This one line makes the whole tutorial suspect: "And $* or $@ refer to all arguments passed to script"
Any shell tutorial that mentions $* without explaining why you should almost never use it is broken.- meteorash, on 10/12/2007, -0/+0Why would you suspect any tutorial in the first place? Why would you want to find flaws in others work anyway? Is it cos he could and you couldn't or are you just plain envious.
- ThsGuyRightHere, on 10/12/2007, -0/+0As long as the table of contents lists chapters like "What Linux is?", "Who developed the Linux?", and "What is Processes" I wouldn't consider this diggworthy. It's clear that the author's first language isn't English, and there's nothing wrong with that. He does a much better job describing shell scripts in my language than I would in his language.
Having said that, I hope he'll be able to recruit someone to edit the book for readability. In its current state, the language barrier falls somewhere between distracting and outright confusing. - siguy, on 10/12/2007, -0/+0"Kernel is hart of Linux Os" Engrishtastic!
- Philluminati, on 10/12/2007, -0/+1
The Grammer in this article is unacceptable.
The author can't string more than 3 lines together without ***** it up.
If you look at the page on "System Variables" he says that the variables COLUMNS and LINES are identical in their purpose yet he doesn't explain why Linux would define two variables that are identical?
This is a shoddy piece of writing and I don't care it at all.- quik22, on 10/12/2007, -1/+2if you're going to bash his english, make sure you don't end your tirade with a sentence like:
"This is a shoddy piece of writing and I don't care it at all."
hypocrite. - meteorash, on 10/12/2007, -0/+0lol!
- quik22, on 10/12/2007, -1/+2if you're going to bash his english, make sure you don't end your tirade with a sentence like:
Digg is coming to a city (and computer) near you! Check out all the details on our