I need to pass letter like "c" for "-copy" and need to read by variable $sel_mod, My I know the good way of writing the script.
Example:
Select one of the Clone Mode ( '-copy', '-differential', '-precopy', '-nopcopy')
Type the Clone mode : c
Thanks in advance,
Ashan
set_env1(){
clear
echo
echo
echo
echo
echo " SETUP CLONE ENVIRONMENT "
echo
echo -e "\e[1;31m Select one of the Clone Mode ( '-copy', '-differential', '-precopy', '-nopcopy' )\e[0m"
echo
echo -n " Type the Clone mode :"
read sel_mod
echo
echo -n " Enter Array I.d (-sid) :"
read sid
echo
echo -n " Enter Clone Device Pair File :"
read dev1
echo
echo
echo " -------------------------------------------"
echo
echo -e "\e[1;34m Entered Clone Mode is : (*** $sel_mod ***) \e[0m"
echo
echo -e "\e[1;34m Entered Array Id is : (*** $sid ***) \e[0m"
echo
echo -e "\e[1;34m Entered Clone File is : (*** $dev1 ***) \e[0m"
echo
echo
echo " -------------------------------------------"
echo
echo -e "\e[1;31m Continue if entries are correct or go back to menu reselect.....!!! \e[0m"
echo
MOD=$sel_mod
ID=$sid
DFILE1=$dev1
DFILE2=$dev2
}
set_env1
rdrtx1
September 27, 2012, 5:24pm
2
Maybe this:
get_opt(){
OPTS=":-copy:-differential:-precopy:-nopcopy"
opt="${1#[-]*}${OPTS##*:-$1}"
opt="-${opt%%:*}"
opt="-${opt#[-]*}"
echo $opt
}
set_env1(){
clear
echo
echo
echo
echo
echo " SETUP CLONE ENVIRONMENT "
echo
echo -e "\e[1;31m Select one of the Clone Mode ( '-copy', '-differential', '-precopy', '-nopcopy' )\e[0m"
echo
echo -n " Type the Clone mode :"
read sel_mod
sel_mod=$(get_opt $sel_mod)
echo
echo -n " Enter Array I.d (-sid) :"
read sid
sid=$(get_opt $sid)
echo
echo -n " Enter Clone Device Pair File :"
read dev1
dev1=$(get_opt $dev1)
echo
echo
echo " -------------------------------------------"
echo
echo -e "\e[1;34m Entered Clone Mode is : (*** $sel_mod ***) \e[0m"
echo
echo -e "\e[1;34m Entered Array Id is : (*** $sid ***) \e[0m"
echo
echo -e "\e[1;34m Entered Clone File is : (*** $dev1 ***) \e[0m"
echo
echo
echo " -------------------------------------------"
echo
echo -e "\e[1;31m Continue if entries are correct or go back to menu reselect.....!!! \e[0m"
echo
MOD=$sel_mod
ID=$sid
DFILE1=$dev1
DFILE2=$dev2
}
set_env1
Thanks for your reply can you please explain the code and who it work.
get_opt(){
OPTS=":-copy:-differential:-precopy:-nopcopy"
opt="${1#[-]*}${OPTS##*:-$1}"
opt="-${opt%%:*}"
opt="-${opt#[-]*}"
echo $opt
}
rdrtx1
September 27, 2012, 9:19pm
4
get_opt(){ # define get_opt function
OPTS=":-copy:-differential:-precopy:-nopcopy" # set the OPTS string variable
opt="${1#[-]*}${OPTS##*:-$1}" # find the matching string in OPTS using the $1 variable to the function
opt="-${opt%%:*}" # remove the ":" to the end of string after the matching string
opt="-${opt#[-]*}" # force "-" at beginning of opt string
echo $opt # return opt string
}
Issue is rest of the output also get hyphen mark, need to avoid hyphen shown below.
Entered Array Id is : (*** -4122 ***)
Entered Clone File is : (*** -dev.txt ***)
----------------------------------------------------------------------------------------------
SETUP CLONE ENVIRONMENT
Select one of the Clone Mode ( '-copy', '-differential', '-precopy', '-nopcopy' )
Type the Clone mode :c
Enter Array I.d (-sid) :4122
Enter Clone Device Pair File :dev.txt
-------------------------------------------
Entered Clone Mode is : (*** -copy ***)
Entered Array Id is : (*** -4122 ***)
Entered Clone File is : (*** -dev.txt ***)
-------------------------------------------
rdrtx1
September 27, 2012, 9:30pm
6
to remove hyphen:
replace line in get_opt function:
opt="-${opt#[-]*}"
with
opt="${opt#[-]*}"