Scripting Classroomnotes 03/Feb/2023

Shell Scripting Contd

  • Scripting is a list of commands that are executed in a particular order.
  • Generally the script executes the commands in the order they are written, but we can also specify
    • instructions to repeat the same command multiple times (loops)
    • to skip some commands based on some conditions (conditionals)
  • Sample script
#!/bin/bash
echo 1
echo 2
echo 3
echo 4
echo 5
  • Execute this script hello.sh
  • Consider the following activities
    • Create a directory under /opt/backup folder that has today’s date in the name eg /opt/backup/qtdevops-03022023
    • Copy all the files from /home/qtdevops/ into this directory
  • Solution:
    • Find a command to get the date and then data in some format.
    • Refer Here for the script added

Variables

  • Variables will store the value and we can use the values further in the script
  • Types of Variables:
    • Environmental Variables:
      • The shell maintains environmetal variables which are common to applications/scripts across the current session
      • To use the environmental variable $<ENV-VAR-NAME>
      • To set environmental variables you can use export command
    • User Variables:
      • These are the variables set in a shell script
      • Refer Here for the usage of user variables

Exercise

  • Findout all the environmental and user variables in the Refer Here
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Plugin for Social Media by Acurax Wordpress Design Studio
Exit mobile version
%%footer%%