Server for Information Technologies ������ ��������������
������� �������������� ����������
(095) 932-9212, 932-9213, 939-0783
E-mail: [email protected]
������ �������� ����(!) ������������� ���������� CIT Forum CD-ROM

GETOPTS(1)

��������
getopts - ������ ����� �������

���������

      getopts  �������_����� ��� [�������� ...]

��������
������� getopts ������������ shell-����������� ��� ������� ����������� ���������� � �������� ����� �� ������������. ������� getopts ������������ ��� ���������� ������� ������������ ���������� ������ [��. intro(1), ������� 3-10].

�������_����� ������ ��������� �����, ������� ����� �������������� shell-����������, ������������ getopts. ���� �� ������ ������� ���������, �� ��������������, ��� ����� ����� �������� ��� ������ ����������, ������� ������ ���������� �� ����� ��������� ��� �����������.

����� ������� ������ getopts �������� ��������� ����� � ���������� ���, � ����� ���������, ������� ������ ���� ��������� ���������, - � ���������� OPTIND. ������, ����� ����������� shell ��� shell-���������, OPTIND �������� �������� 1.

���� ����� ��������� ��������, �� getopts �������� ��� � ���������� OPTARG.

���� ����������� ������������ �����, �� � ���������� ��� ���������� ?.

���� ����� ���������, getopts ���������� ��������� ��� ����������. ����� ������������ ����������� ����� --, ����� �������� ����� �����.

�� ��������� ������� getopts ��������� ����������� ��������� ��������� �� shell-���������, �� ���� ������� �������������� ���������, �� getopts ����� ��������� ��.

������
��������� �������� shell-��������� cmd ����������, ��� ����� ���������� ��������� �������, ����������� ����� a � b, � ����� ����� o, ������� ������ ����� ��������:

     while getopts abo: c
     do
       case $c in
       a | b)  FLAG=$c;;
       o)      OARG=$OPTARG;;
       ?)      echo $USAGE
               exit 2;;
       esac
     done
     shift `expr  $OPTIND - 1`
��� ����� ��������� ��������� ������ ����������� ��������������:
     cmd -a -b -o "xxx z yy" file
     cmd -a -b -o "xxx z yy" -- file
     cmd -ab -o xxx,z,yy  file
     cmd -ab -o "xxx z yy" file
     cmd -o xxx,z,yy -b -a  file

����������
����������� � ��������������� ���������� ����� �� ������ �����:

  1. � ��������� ������ ����� b � a ���� � ���� �������, ��� � ����������, � ��� ��� � ������ ������� ��� ����� ���������� � ���� ���������� FLAG, �� ��� ��������� ��������� ������ ������������� �������� ���� ���������� �������� �� �����, ��� � ���������� �������.

  2. � ��� �������, � ������� �������� ����� o ����� � ���� "xxx z yy", OARG ������ �������� xxx z yy, � � ��� �������, ��� �������� ����� o ����� ��� xxx,z,yy, OARG ����� ����� xxx,z,yy.

�����

 	/usr/bin/getopt         ������ ������ ��������� �������
				�����.
	/usr/lib/getoptcvt      ��������� �������� shell-�����-
				���, �������������� getopt,  ��
				getopts.

��. �����
gutil(1G), intro(1), sh(1). getopt(3C) � ����������� ������������.

�����������
������� getopts ������� ��������� �� ������ � ����������� ��������, ����� ����������� �����, �� ���������� � �������_�����.

���������������
���� ������� ���������� getopts ��������� ��������� ����������� �� ������, �������� ��������� ������ [��. intro(1)], ���� �� ������� ������������, ��� ��� �������� ����������� ����� �� �������������� � ��������� ������� �������. �����, ��� � � �������, a � b - ����� ��� ����������, � ����� o ��������� ��������:

     cmd  -aboxxx file
����� �������� ������� 5: ����� � ���������� �� ������ ���� � ����� ������ � ���������� �������.
     cmd  -ab -oxxx file
�������� ������� 6: ����� �����, ������� ��������� ��������, ������ ���� ������ ��� ���������.

��������� �������� ���������� OPTIND ��� ������ ��������� ������� ���������� ����� �������� � ���������������� ����������.
Comments: [email protected]
Designed by Andrey Novikov
Copyright © CIT