Urban pro

View My Profile

Sunday, April 7, 2013

BASH COMMANDS - PART 1


Hi friends,

Today  we are gonna go in  a different direction . After some time , i thought of coming out with a series of tutorials on BASH scripting , which is a must if you wanna write complex scripts. My try outs here will
consist of commands written in UBUNTU 12.04 PP LTS as this is what i am using right now. So let us open up our terminal and begin our wonderful journey :

Finding out where the inbuilt commands lie :


Type :
bash$ : cd /bin
bash$/bin : ls


Creating my own directory and seeing the permissions it has :
mkdir kunal
ls -ld kunal → drwxrwxr-x 2 atri atri 4096 Apr 3 02:00 kunal

Consider these shell operations :



Consider the next set of shell commands :

How to make use of manual in Unix :
bash$ : man man
O/P :


What if we give :
bash$ : man cp




What is Shebang ? :

The shebang is the first line in a script because it is interpreted by the kernel, which looks at the two bytes at the start of an executable file. If these are #! the rest of the line is interpreted as the executable to run and with the script file available to that program on stdin. Since the kernel will only look at the first two characters and has no notion of further lines, you must place the hash bang in line 1.
Let us consider the script below :


This script does a listing of files and in between the first and last listing , it tries to read a file. So if you try to execute the file without changing its permissions it won't run. Hence first you gotta do this :

bash $ : ls -lrt yourFile --> get the available permissions
bash $ : chmod a+x yourFile --> make the file executable.
Voila, now you are ready to run it. Just do :
bash $ :  ./yourFile

 or

bash $: sh yourFile.sh

That's  all for today. Next time we will delve deeper .

Good Bye .


No comments:

Post a Comment