Posts

Showing posts with the label shell script

Shell Script

Image
Shell Script Examples This section presents several shell script examples. Hello World Example 9. Hello World #!/bin/sh echo "Hello world" Using Arguments Example 10. Shell Script Arguments #!/bin/bash # example of using arguments to a script echo "My first name is $1" echo "My surname is $2" echo "Total number of arguments is $#" Save this file as  name.sh , set execute permission on that file by typing  chmod a+x name.sh  and then execute the file like this:  ./name.sh . $ chmod a+x name.sh $ ./name.sh Hans-Wolfgang Loidl My first name is Hans-Wolfgang My surname is Loidl Total number of arguments is 2 Version 1: Line count example The first example simply counts the number of lines in an input file. It does so by iterating over all lines of a file using a  while  loop, performing a  read  operation in the loop header. While there is a line to process, the loop body will be executed in this case simply ...