Create Shell Script With Inputs

LinuxLinuxBeginner
Practice Now

Introduction

In this challenge, you will learn how to create a simple shell script that can accept and process input parameters. Shell scripts are a powerful tool in the Linux environment, allowing you to automate repetitive tasks and streamline your workflow. By mastering the use of script inputs, you can make your scripts more flexible and dynamic, tailoring them to specific needs.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`") subgraph Lab Skills linux/echo -.-> lab-389450{{"`Create Shell Script With Inputs`"}} end

Create a Shell Script with Input Parameters

Tasks

  • Create a shell script that accepts two input parameters.
  • Use the input parameters within the script to perform a simple operation.
  • Output the result of the operation to the terminal.

Requirements

  • Create the script in the ~/project directory and name it script.sh.
  • The script should accept two input parameters.
  • Use the $1 and $2 variables to reference the input parameters within the script.
  • Perform a simple operation (e.g., addition, concatenation) using the input parameters.
  • Output the result of the operation to the terminal.

Example

$ ./script.sh 10 20
The result is: 30

Summary

In this challenge, you learned how to create a simple shell script that accepts input parameters and performs a basic operation using those parameters. By understanding how to work with script inputs, you have gained a valuable skill that can be applied to more complex shell scripting tasks. This challenge helps reinforce the RHCSA exam objective of creating simple shell scripts and processing script inputs.

Other Linux Tutorials you may like