Bash Shell Scripting – The Basics and Variables Create a bash script that does the following: Create a text file 'compile.sh' in the Text Editor (or Atom or vi editors) Indicate the Shell/Script type in line 1: #!/bin/sh You can print text to console by using: echo "My Text" command. Enter the required commands to compile and run your Hello World C program. Exit your Text Editor (make sure to save your work). Run your script 'compile.sh' from a Terminal session by entering: ./compile.sh What happened? Give the script permission using: chmod 777 test.sh command. Remove the hard code file names and use a bash script argument: Open the 'compile.sh' script in the Text Editor (or Atom or vi editors). Save the program to compile script that is passed as a script argument in a variable ($1 will be your first bash argument). Substitute the variable where you currently have the 'HelloWorld' program name text. Test your script. Add error checking: Open the 'compile.sh' script in the Text Editor (or Atom or vi editors). Check that the script arguments are not empty. Check the return value from gcc. Test your script. Working with environment variables: Create a 'var1.sh' script. Create a variable in var1.sh script. Call the printenv command to print the environment variables out. Call var2.sh from this script. Create a 'var2.sh' script: Call the printenv command to print the environment variables out. Run 'var1.sh' script Modify 'var1.sh' script and prefix the variable with the word export. Run 'var1.sh' script again. What differences do you see in the environment for each script?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Bash Shell Scripting – The Basics and Variables

  1. Create a bash script that does the following:
    1. Create a text file 'compile.sh' in the Text Editor (or Atom or vi editors)
    2. Indicate the Shell/Script type in line 1: #!/bin/sh
    3. You can print text to console by using: echo "My Text" command.
    4. Enter the required commands to compile and run your Hello World C program.
    5. Exit your Text Editor (make sure to save your work).
    6. Run your script 'compile.sh' from a Terminal session by entering: ./compile.sh
      1. What happened?
    7. Give the script permission using: chmod 777 test.sh command.
  2. Remove the hard code file names and use a bash script argument:
    1. Open the 'compile.sh' script in the Text Editor (or Atom or vi editors).
    2. Save the program to compile script that is passed as a script argument in a variable ($1 will be your first bash argument).
    3. Substitute the variable where you currently have the 'HelloWorld' program name text.
    4. Test your script.
  3. Add error checking:
    1. Open the 'compile.sh' script in the Text Editor (or Atom or vi editors).
    2. Check that the script arguments are not empty.
    3. Check the return value from gcc.
    4. Test your script.
  4. Working with environment variables:
    1. Create a 'var1.sh' script.
    2. Create a variable in var1.sh script.
    3. Call the printenv command to print the environment variables out.
    4. Call var2.sh from this script.
    5. Create a 'var2.sh' script:
      1. Call the printenv command to print the environment variables out.
    6. Run 'var1.sh' script
    7. Modify 'var1.sh' script and prefix the variable with the word export.
    8. Run 'var1.sh' script again.
    9. What differences do you see in the environment for each script?
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education