Linux Shell Scripting – Foundation Classroom- 15/Sep/2019

Shell Scripting

How to create shell scripts

  • using simple touch
touch test.sh
  • VIM Editor/nano
  • VIM Tutorial here

Arguments

  • $@: Whole arguments passed to script
  • $#: Count of arguments

Excercise

  1. Write a script which prints number of arguments passed
#!/bin/bash
echo "Number of arguments passed are $#"
  1. Write a script which gives an error message if no arguments are passed
  2. Write a shell script to add all the arguments passed
add.sh 1 2 3 4 5 => 15

Summary

  1. Positional Arguments: Symbols: $@, $#, $1
  2. Conditional Statement: if, if else, if else if , nested if
  3. Exit Codes: 0 => success , 1 => failure
  4. running mini bash script => ls;pwd;
  5. running multiple scripts => a.sh && b.sh , a.sh || b.sh
  6. looping structure: for , for index in $@ == for index

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

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

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube