Shell Scripting
How to create shell scripts
touch test.sh
- VIM Editor/nano
- VIM Tutorial here
Arguments
- $@: Whole arguments passed to script
- $#: Count of arguments
Excercise
- Write a script which prints number of arguments passed
#!/bin/bash
echo "Number of arguments passed are $#"
- Write a script which gives an error message if no arguments are passed
- Write a shell script to add all the arguments passed
add.sh 1 2 3 4 5 => 15
Summary
- Positional Arguments:
Symbols: $@, $#, $1
- Conditional Statement: if, if else, if else if , nested if
- Exit Codes: 0 => success , 1 => failure
- running mini bash script => ls;pwd;
- running multiple scripts => a.sh && b.sh , a.sh || b.sh
- looping structure: for , for index in $@ == for index
Like this:
Like Loading...