Open your file from desktop by some editor say gedit or double click the file

Open your file from desktop by some editor say gedit

This preview shows page 9 - 20 out of 29 pages.

Open your file from desktop by some editor; say gedit (or double click the file) On this file, you have to write bash script. 1st line must always be #!/ location #!/bin/bash We have determined it by “which bash”
Image of page 9
Write code #!/bin/bash Echo “hello world” Save it Goto terminal Execute it as” $ ./hello.sh or $ bash hello.sh
Image of page 10
Permission denied message appears. Because hello.sh do not have the permission to execute. It needs rights for it. Check what rights still it has: $ touch hello.sh $ ls –al It lists the rights as rw-rw-r (no command for execute x)
Image of page 11
Change the rights of file to execute $ chmod +x hello.sh To check $ ls –al We can see: rwx-rwx-x Now execute the file $ ./hello.sh
Image of page 12
Comments ‘#’ symbol is used to add single line comment in bash script. Create a new file named ‘ comment.sh’ and add the following script with single line comment. #!/bin/bash # Add two numeric value ((sum=25+35)) #Print the result echo $sum
Image of page 13
Goto terminal: execute it: $ bash comment.sh
Image of page 14
Variables Variables are containers which stores data either integers or characters. Two types of variables: System variables User-defined variables
Image of page 15
System Variables Variables those are created and maintained by unix or linux OS These are the variables defined in capital cases (mostly). Hello.sh: echo $BASH Terminal: $ ./hello.sh It will give information about your bash.
Image of page 16
Hello.sh Terminal Echo $BASH VERSION $ ./hello.sh Echo $HOME Echo $ PWD TASK: SEARCH 15 SYSTEM VARIABLES AN EXECUTE THOSE.
Image of page 17
User Defined Variables Hello.sh #!/bin/bash Name= “Mark” (or) Name= Mark Echo $Name (or) Echo the name is $Name Terminal $ ./hello.sh
Image of page 18
Read User Input Hello.sh echo “enter name” read name echo “the name is : $name Terminal $ ./hello.sh
Image of page 19
Image of page 20

You've reached the end of your free preview.

Want to read all 29 pages?

  • Spring '17
  • SHaftab ahmed
  • Shell

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes