shell script how getopts can accept more than one string in one variable from Command line

A

AJAY SHARMA

Guest
In shell script how getopts can accept more than one string in one variable DES

Here is the part of shell script that accepts variables from the Shell script but the the DES variable does not accepts more than one variable., how to to do this ??

When i run the script like below

sh Ericsson_4G_nwid_configuration.sh -n orah4g -d "Ericsson 4g Child" -z Europe/Stockholm

it does not accepts "Ericsson 4g Child" in DES Variable and only accepts "Ericsson" to DES variable.

how to make it accept full "Ericsson 4g Child"

Code:
while getopts “hn:r:p:v:d:z:” OPTION
do
  case $OPTION in
  h)
  usage
  exit 1
  ;;
  n)
  TEST=$OPTARG
  ;;
  z)
  ZONE="$OPTARG"
  ;;
  d)
  DES="$OPTARG"
  ;;
  v)
  VERBOSE=1
  ;;
  ?)
  usage
  exit
  ;;
  esac
done
 
Last edited:


You can wrap the arg containing space with double-quotes, e.g., cmd first_arg "foo bar" or simply escape spaces with back slashes, e.g., cmd first_arg foo\ bar.

In both cases "cmd" gets "cmd" in arg[0], "first_arg" in arg[1], and "foo bar" in arg[2]
 
You'll probably need to escape the forward slash in "Europe/Stockholm" with a backslash, as well: "Europe\/Stockholm"
 

Members online


Latest posts

Top