-1

suppose I have a script file "display.sh" which displays some output.

Name -Xander  
Age-29       //   Step 1        

I want to add something extra to this output.

Name -Xander
Age-29
occupation-Cricketer //extra stuff

Now when I give command display.sh, only Step 1 should display But when I give command (display.sh -t or -f or anything) both step 1 and extra stuff should display

How this last part can be achieved??

Utsav
  • 7,914
  • 2
  • 17
  • 38

1 Answers1

0

If you want the full-blown solution, use getopt or getopts as suggested by Aserre.

However, imho this is often overkill. If you have only one or two flags without arguments, a simple if-then might be sufficient.

You will need to look into how to use command line arguments in bash

To help you with an example:

#!/bin/bash
if [ "$1" = "-f" ] ; then
    do_the_rest=1
else
    do_the_rest=0
fi
# lots of code for your display script
if [ $do_the_rest = 1 ] ; then
    # code to display the rest of the lines
fi
Ljm Dullaart
  • 4,273
  • 2
  • 14
  • 31