bash �ǡ����֥����뤬��ư�������
( ), $( ), { }, <( )
�Ǥ���
ps --forest
��¹Ԥ��ơ�ps
���ޥ�ɤοƥץ��������ɤ�ˤʤäƤ��뤫�dz�ǧ���Ƥ��ޤ���bash �����ꤹ�� $PPID
�ѿ��򸫤ʤ��Τϡ��ѿ���Ÿ����ɤΥ����뤬���뤫�˰�¸���뤿��ˡ���ǧ���ˤ�������Ǥ���ps
���ޥ�ɤ� --forest
���ץ�����դ���ñ��˵�ư�����
$ ps --forest PID TTY TIME CMD 20218 pts/18 00:00:00 bash 27975 pts/18 00:00:00 \_ ps�Ȥʤ�ޤ������־�� PID = 20218 �� bash �������ߥʥ���ư���Ƥ��� bash �ˤʤ�ޤ������֥����뤬��ư�������ϡ����� bash �� ps �δ֤ˡ��⤦��� bash ��ư���Ϥ��Ǥ���
- ( )
$ (ps --forest) PID TTY TIME CMD 20218 pts/18 00:00:00 bash 27976 pts/18 00:00:00 \_ ps�Ȥʤäơ����֥�����ϵ�ư����ޤ��󡥤��������ޥ�ɤ�⤦����ɲä��Ƥ���
$ (ps --forest; echo -n) PID TTY TIME CMD 20218 pts/18 00:00:00 bash 27977 pts/18 00:00:00 \_ bash 27978 pts/18 00:00:00 \_ ps�Ȥʤäơ����֥����뤬��ư����ޤ���������ĤΥѥ�����ϡ�
{ }
�Υ������Ȥ�����ѤǤ���( )
�Ǥϥѥ�����³����Ƥ��̤˱ƶ��Ϥʤ��褦�Ǥ���
$ (ps --forest) | cat PID TTY TIME CMD 20218 pts/18 00:00:00 bash 27979 pts/18 00:00:00 \_ ps 27980 pts/18 00:00:00 \_ cat $ echo | (ps --forest) PID TTY TIME CMD 20218 pts/18 00:00:00 bash 27982 pts/18 00:00:00 \_ ps
- $( )
$( )
�ϡ����ꤵ�줿���ޥ�ɤμ¹Է�̤򥳥ޥ�ɥ饤���˺������ि��Τ�ΤǤ� ` `
�ȵ�ǽŪ�ˤ�Ʊ���Ǥ������Ϸ�̤�ɽ�����뤿��� echo
��ȤäƤ��ޤ���$( )
���Τ� " �Ǥ����äƤ���Τϡ����Ԥ���¸�����褦�ˤ��뤿��Ǥ�����̤ϼ��Τ褦�ˤʤ�ޤ������ѥ�����Ū�ˤ� ( )
��Ʊ���Ǥ���
$ echo "$(ps --forest)" PID TTY TIME CMD 20218 pts/18 00:00:00 bash 27983 pts/18 00:00:00 \_ ps $ echo "$(ps --forest; echo -n)" PID TTY TIME CMD 20218 pts/18 00:00:00 bash 27984 pts/18 00:00:00 \_ bash 27985 pts/18 00:00:00 \_ ps
- { }
{ }
�ϥ֥��å����뤿��ι�ʸ�Ǥ������ޥ�ɤ���Ĥξ���
$ { ps --forest; } PID TTY TIME CMD 20218 pts/18 00:00:00 bash 27986 pts/18 00:00:00 \_ ps�Ȥʤ�ޤ������ޥ�ɤ���Ĥˤ������
$ { ps --forest; echo -n; } PID TTY TIME CMD 20218 pts/18 00:00:00 bash 27987 pts/18 00:00:00 \_ ps�Ȥʤäơ�����
( )
�� $( )
�Ȱ㤤���֥�����ϵ�ư����ޤ��󡥤Ǥϡ��֥��å�������˥ѥ��פ򶴤�Ǥ��Ȥɤ��ʤ�Ǥ��礦����
$ { ps --forest; } | cat PID TTY TIME CMD 20218 pts/18 00:00:00 bash 27988 pts/18 00:00:00 \_ bash 27990 pts/18 00:00:00 | \_ ps 27989 pts/18 00:00:00 \_ cat $ echo | { ps --forest; } PID TTY TIME CMD 20218 pts/18 00:00:00 bash 27992 pts/18 00:00:00 \_ bash 27993 pts/18 00:00:00 \_ ps�Τ褦�ˡ���äѤ�
( )
�� $( ) �ξ��Ȱ㤤�����٤ϥ��ޥ�ɤ���Ĥ����Ǥ⥵�֥����뤬��ư�����褦�ˤʤäƤ��ޤ��ޤ��������ΰ㤤�ϡ������ʤ��饷�����ѿ����ѹ���ȼ�����˱ƶ���ڤܤ��ޤ����Ĥޤꡤ���Τ褦�ʤ��Ȥ�������ޤ���
$ a=aaa $ { a=bbb; } $ echo $a bbb $ echo | { a=ccc; } $ echo $a bbb���ʤߤˡ����δط���
while
�� for
�ʤɤ�����ʸ�Υ֥��å��Ǥ�Ʊ�ͤ�ȯ�����ޤ���
$ check=true; while $check; do ps --forest; check=false; done PID TTY TIME CMD 29996 pts/9 00:00:00 bash 30458 pts/9 00:00:00 \_ ps $ check=true; while $check; do ps --forest; check=false; done | cat PID TTY TIME CMD 29996 pts/9 00:00:00 bash 30459 pts/9 00:00:00 \_ bash 30461 pts/9 00:00:00 | \_ ps 30460 pts/9 00:00:00 \_ cat $ check=true; echo | while $check; do ps --forest; check=false; done PID TTY TIME CMD 29996 pts/9 00:00:00 bash 30463 pts/9 00:00:00 \_ bash 30464 pts/9 00:00:00 \_ ps $ for i in 1; do ps --forest; done PID TTY TIME CMD 29996 pts/9 00:00:00 bash 30466 pts/9 00:00:00 \_ ps $ for i in 1; do ps --forest; done | cat PID TTY TIME CMD 29996 pts/9 00:00:00 bash 30467 pts/9 00:00:00 \_ bash 30469 pts/9 00:00:00 | \_ ps 30468 pts/9 00:00:00 \_ cat $ echo | for i in 1; do ps --forest; done PID TTY TIME CMD 29996 pts/9 00:00:00 bash 30471 pts/9 00:00:00 \_ bash 30472 pts/9 00:00:00 \_ ps�ؿ��Ǥ�Ʊ���Ǥ���
$ testf(){ ps --forest; } $ testf PID TTY TIME CMD 29996 pts/9 00:00:00 bash 30478 pts/9 00:00:00 \_ ps $ testf | cat PID TTY TIME CMD 29996 pts/9 00:00:00 bash 30479 pts/9 00:00:00 \_ bash 30481 pts/9 00:00:00 | \_ ps 30480 pts/9 00:00:00 \_ cat $ echo | testf PID TTY TIME CMD 29996 pts/9 00:00:00 bash 30483 pts/9 00:00:00 \_ bash 30484 pts/9 00:00:00 \_ ps
- <$( )
$ less <(ssh dokoka cat hoge)�Τ褦�ʷ��ǻȤ��ޤ����Ĥޤꡤ���ޥ�ɤμ¹Է�̤�̾���դ��ѥ��פ��̤��Ƽ��Ф����Ȥ��Ǥ���褦�ˤ��빽ʸ�Ǥ�����⡼�ȤΥۥ��ȤΥե�����Ȥ� diff ����Τˤ������ǽ������Ƥޤ������Ʒ�̤��ɤ��ʤ뤫�Ǥ�����
$ cat <(ps --forest) PID TTY TIME CMD 20218 pts/18 00:00:00 bash 27994 pts/18 00:00:00 \_ bash 27995 pts/18 00:00:00 | \_ ps 27996 pts/18 00:00:00 \_ cat $ cat <(ps --forest; echo -n) PID TTY TIME CMD 20218 pts/18 00:00:00 bash 27997 pts/18 00:00:00 \_ bash 27998 pts/18 00:00:00 | \_ ps 27999 pts/18 00:00:00 \_ cat�Ȥʤ�ޤ������Ĥޤꡤɬ�����֥����뤬��ư����ޤ���
�ȥ�å��Хå�URL
���ε����ؤΥ�����
���졢�狼�äƤʤ��ȤϤޤ�ޤ���͡�
v="old";(v="new";echo $v);echo $v
$v���Ѥ��ʤ��Ǥ��͡�
���read�Ǥ褯�ϤޤäƤޤ�����
v="old";VV="old"
echo -e "a\nc\nd" | while read v ;do
VV=$v
echo $v $VV
done
echo $v $VV
v="old";VV="old"
while read v ;do
VV=$v
echo $v $VV
done < <(echo -e "a\nc\nd")
echo $v $VV
���ʤߤˡ���ʸ�Ǥ� ( ) ����Υ��ޥ�ɤ���Ĥ����λ��ϥ��֥�����ϵ�ư����ʤ��Ƚñ¤¤Þ¤ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½
v="old";(v="new");echo $v
�Ǥ��äѤ� v ���ͤ� old �Τޤޤ��ä��ꤷ�ޤ���bash(1) �ˤ��С�( ) ����Ȥϥ��֥�����Ǽ¹Ԥ��롤�Ƚ񤤤Ƥޤ��Τǡ�����˹�碌�Ƥ�Τ��Ȼפ��ޤ���
()��$()��<() >() �� | (�ѥ���)�α���(?)���̥ץ������Ǽ¹Ԥ���뤳�Ȥ��ΤäƤ���С֥������ѿ����ѹ������Τ�ȿ�Ǥ���ʤ�?!�פʤ�ƥߥ��Ϥʤ��ʤ뤫�ȡ�
�ʤΤǰʲ��� ksh, zsh �Ǽ¹Ԥ���ȡ�foo�פ�ɽ������ޤ���
echo foo |read bar
echo $bar
(ps --forest) �λ��� ps �ȿƤΥ�����ץ�������ľ�ܤοƻҴط��˸������Τϡ�( ) ����Υ��ޥ��(��������Ǥ� ps)��1�Ĥ����λ��ϡ����֥����뤬 fork() & exec() �ǤϤʤ������֥����뤬ľ�� ps �� exec() ���Ƥ���ΤǤ��礦�͡�