Shell Script with Function: You can define a function and the commands/code in it. Then you can call that function at last line which will execute all commands mention in that block for you. f1() { var="Welcome to the geekstuff" echo ${#var} } f1 Output : ./test.sh 24