|
��������
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
����������
����������� � ��������������� ���������� ����� �� ������ �����:
�����
/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 ��� ������ ��������� ������� ���������� ����� �������� � ���������������� ����������.
|