I need to read command line argument which is passing as scriptname –c "30,31,32,33,34,35"
and convert it to
myArray=( 30 31 32 )
Try the following:
while getopts c: option
do
case $option in
c) data="$OPTARG"
;;
esac
done
oldIFS="$IFS"
IFS=','
myArray=($data)
IFS="$oldIFS"
echo ${myArray[@]}
The c:
after getopts
indicates that we have an option -c
, the :
indicates it is followed by an argument, which is retrieved using $OPTARG
.
IFS
if the Inter Field Separator which I reset to a comma in order to create the array.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다