Tutorial by Examples

To parse lots of parameters, the prefered way of doing this is using a while loop, a case statement, and shift. shift is used to pop the first parameter in the series, making what used to be $2, now be $1. This is useful for processing arguments one at a time. #!/bin/bash # Load the user define...
When executing a Bash script, parameters passed into the script are named in accordance to their position: $1 is the name of the first parameter, $2 is the name of the second parameter, and so on. A missing parameter simply evaluates to an empty string. Checking for the existence of a parameter can...
A simple example which provides the options: OptAlt. OptDetails-h--helpShow help-v--versionShow version info-dr path--doc-root pathAn option which takes a secondary parameter (a path)-i--installA boolean option (true/false)-*--Invalid option #!/bin/bash dr='' install=false skip=false for op ...
Wrapper script is a script that wraps another script or command to provide extra functionalities or just to make something less tedious. For example, the actual egrep in new GNU/Linux system is being replaced by a wrapper script named egrep. This is how it looks: #!/bin/sh exec grep -E "$@&q...
Let's say we have a String parameter and we want to split it by comma my_param="foo,bar,bash" To split this string by comma we can use; IFS=',' read -r -a array <<< "$my_param" Here, IFS is a special variable called Internal field separator which defines the char...

Page 1 of 1