Linux-Noob Forums
Bash Primer? - Printable Version

+- Linux-Noob Forums (https://www.linux-noob.com/forums)
+-- Forum: Linux Noob (https://www.linux-noob.com/forums/forum-3.html)
+--- Forum: How Do I? (https://www.linux-noob.com/forums/forum-60.html)
+--- Thread: Bash Primer? (/thread-312.html)



Bash Primer? - Bevior - 2011-10-03


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.




Bash Primer? - anyweb - 2011-10-03


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

 



Code:
man command




 

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

 



Code:
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

 



Code:
top




 

whereas

 



Code:
Top




 

will most likely fail




Bash Primer? - Dungeon-Dave - 2011-10-03


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 ("autoexec.sh", 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!


</ol>


 

Good luck!




Bash Primer? - Dungeon-Dave - 2011-10-03


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)




Bash Primer? - hybrid - 2011-10-06


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

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




Bash Primer? - hybrid - 2011-10-06


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* -- http://fosswire.com/...nd-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.




Bash Primer? - inittux - 2011-10-06


This is a useful website too:

 

http://linuxcommand.org/




Bash Primer? - hybrid - 2011-10-07


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.

 

http://www.youtube.com/watch?v=yIY3iPDVUBg

 

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.




Bash Primer? - hybrid - 2011-10-07





<div><iframe width="480" height="270" src="https://www.youtube.com/embed/i16cQTULEjM?feature=oembed" frameborder="0" allowfullscreen="true"></iframe></div>
 




<div><iframe width="480" height="270" src="https://www.youtube.com/embed/KRs-rEx-EJA?feature=oembed" frameborder="0" allowfullscreen="true"></iframe></div>