Linux-Noob Forums

Full Version: Bash Primer?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Can anyone point me in the right direction for a good bash primer? I like to use terminal (call me crazy, maybe?) because I don't have to worry about give the file management system escalated permissions and I really loathe using a mouse unless I have to. Coming from Windows I had most of my DOS commands down but still have trouble with syntax and switches etc..

Any help would be appreciated.

first tip:- if you need help with a command type


man command


replace the word command with whatever you need help on, eg:


man top


second tip:- get used to using a text editor called vi, it's in nearly all linux distros out there and you'll need it to read the help files which are nearly always text based


third tip:- linux (unlike windows) is case sensitive so a command like this will work








will most likely fail

There's a pile of system scripts in /etc/init.d - it's worth sneaking a look at a few there and try to puzzle out what they're doing.


A number of things to point out before you start writing your own scripts:

<ol style="list-style-type: decimal">
[*]your scripts need to have EXECUTE permission on (chmod u+x myscript) in order to run

[*]your scripts need to be in a directory mentioned in your ${PATH} variable to run them by name alone. Your "bin" dir inside your own home directory is a common place to put them.

[*]use the "which" command to see if that script name (or command name) is already taken, eg: "which date" or "which mydate".

[*]Don't call your scripts "script" or "test". It's a common mistake, but they're reserved words.

[*]Some people like to append a file extension, such as ".sh" to their script names. Unlike windows, the actual filename isn't important, but don't forget to use its full name ("", not just "autoexec")

[*]Minor point, but sometimes writing and saving (without quitting) in one window then running in another window means you can quickly compare code and results side-by-side.

[*]If you dislike vi, consider installing "nano" or "pico" as alternative editors

[*]If you already know all that stuff above... well, let's move onto lesson 2!



Good luck!

Oh, and one last bit: feel free to post examples of your non-working code in here. We can give you pointers as to why it doesn't work, as well as alternative ways of writing the same script.


(well, Hybrid can, because he's tha King Kodah here. I'm just a serf)

Quote:(well, Hybrid can, because he's tha King Kodah here. I'm just a serf)

I am? That's news to me! :)

A few resources that might be of interest with getting started with the Linux command line:


Free Software Magazine's introduction to the command line -- http://www.freesoftw...mand_line_intro


FOSSwire's Command Line Cheat Sheet* --


I also put together a trio of videos which explain some of the fundamentals of command line. It's focused at Mac users, but there is a lot of commonality between the command line environments on Mac OS X and Linux, so I think they might be valuable to you too. They have, for the moment, disappeared from the internet, because the podcast for which they were made has undergone some changes, but I'm going to try and get them back online and post a link here.


* I should mention that, while I didn't make this particular cheat sheet, FOSSwire is a site that I co-founded and make a bit of money from.

This is a useful website too:

Here is the first video to which I was referring earlier. You might find it helpful with some of the fundamentals, but it might be a bit repetitive with some of the crossover between the DOS CLI. You might want to skip some Mac-specific stuff and introduction and go straight to 03:30 minutes in.


I am uploading the others and will update the post here with those too, in case they might be helpful. There are some things that are Mac-specific (like the reference to the Library directory), but the majority of the stuff shown here is exactly the same on Linux.

<div><iframe width="480" height="270" src="" frameborder="0" allowfullscreen="true"></iframe></div>

<div><iframe width="480" height="270" src="" frameborder="0" allowfullscreen="true"></iframe></div>