|
���
getopt - ��������� �������������� ������ ��������� �����.
���������
set -- `getopt optstring $*`
��������
������� getopt ������������ ��� ����, ����� ��������� � ��������� ����� � ��������� ������� ��� ������������ �� ��������������� ������� ����������� �������������� shell. ��������
optstring �������� ������� �������������� ���� ����� (��. �������� getopt(2)). ���� �� ������ ������� ���������, �� ���������, ��� ��� ����� ����� ��������, ������� ����� ����������,
� ����� � �� ���������� �� ��� ������ �������������. ����������� ����� -- ������������ ��� �������� ����� ������ �����. ������� getopt ����� ���� ���� �������� -- � ���������� � �����
�����, ���� ������������ ��� �����, ���� ��� ������������ �������� �������. ��������� �������������� shell ($1 $2 ...) ������������������� ����� �������, ��� ������ ����� ������������
���� (-) � ��� ������ � ���� ����������� �������� �������������� shell; ������ �������� ����� ����� ��������� � �����
����������� ��������� �������������� shell.
�������
��������� �������� ���� ��������� ����������, ����� �������
�������������� ��������� ��� �������, ������� ����� ������������ ����� a � b, � ����� �, ��� ������� ��������� ��������:
set - - `getopt abo: $*` if [ $? !=0 ] then echo $USAGE exit 2 fi for i in $* do case $i in -a | -b) FLAG=$i; shift;; -o) OARG=$2; shift; shift;; - -) shift; break;; esac done���� ��� ��������� ����� ����� ��� ������ �� ��������� ������������� �������������:
cmd -aoarg file file cmd -a -o arg file file cmd -oarg -a file file cmd -a -oarg -- file file
��. �����
sh(1), getopt(2).
�����������
������� getopt ������� ��������� �� ������ �� ���������� ���������������� ������ � ������, ���� ��� ��������� ����� �����, �� ���������� � ������ optstring.
���������
���������, �������� ��� ���� �������, ������������, ��� ������������ ����� ������������� shell sh(1).
|