Shell scripting basics

I was a little confused on how to write a shell script and we used it for Advanced Programming and also we are doing it in my Linux Projects course so I thought it might be pretty important so I searched it up and found this link that describes it nice and thoroughly: http://linuxcommand.org/lc3_wss0010.php

So first, you can write your script with vim/emacs, nano, etc; Personally I don’t exactly like using nano, I’ve never used emacs because my AP professor was so against it, so I guess I’m most familiar with vim. To write in vim you can just “vi ___” or “vim ___” to create file and save by doing “:wq” or “:q” to just quit without saving. To write in the file you have to press “i” for “insert” to be able to edit it.

Now, onto shell scripting. Shell scripts are essentially a combination of command lines that you would usually do in the terminal, but it does it all for you in one file, which is neat! I believe you can just write 1 command on 1 line (which is what I have been doing so far, maybe fancier shell scripts might be different).

And then, to give the shell permission to execute, you have to chmod it. One chmod could be chmod 755 hello_world (assuming your script was named hello_world) and “755” gives it read, write, and execute permission. To run it, you can do ./hello_world. The reason why this works is because we specified the pathname “./” of the file to execute. I think that “./” just means same directory as you are in.

Now, if you just want to be able to run the hello_world as a command you can put it in your bin. Then, you can just type hello_world in the command line and the code will run.

 

 

0 comments on “Shell scripting basicsAdd yours →

Leave a Reply

Your email address will not be published.