bash �� �v���Z�X�u��

script �R�}���h���g�������Z�ł��B
�i�g���Ă��� Linux �� Ubuntu 14.04.3 LTS �ł��j

bash �ɂ� �u�v���Z�X�u���v�Ƃ����@�\������܂��B

Process Substitution

    Process  substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming
    open files.  It takes the form of <(list) or >(list).  The process list is run with its input or  output  con�]
    nected  to a FIFO or some file in /dev/fd.  The name of this file is passed as an argument to the current com�]
    mand as the result of the expansion.  If the >(list) form is used, writing to the file will provide input  for
    list.   If  the  <(list)  form  is used, the file passed as an argument should be read to obtain the output of
    list.

    When available, process substitution is performed simultaneously with parameter and variable  expansion,  com�]
    mand substitution, and arithmetic expansion.

�������̈ꎞ�t�@�C���̍쐬�����点��@�\�ŁA �����Ă����̕��@�ő�p�͌����̂ł��� �ǂ������Ŏg���ƃR�}���h���ǂ݂₷���Ȃ����肵�܂��B

�������́A���� 2�B

<(�R�}���h)
>(�R�}���h)

���O�̎��Ă�u�R�}���h�u���v�Ə����������Ă܂��ˁB

�R�}���h�u���ƃv���Z�X�u��

$(�R�}���h)   #�R�}���h�u��

�u�R�}���h�u���v�́A�R�}���h�̌��ʂ� �R�}���h��R�}���h�̈����Ƃ��Ďg�p���邱�Ƃ��ł��܂����B

$ echo $(echo date)

date
$ $(echo date)

Thu Dec  8 22:58:19 JST 2018

�u�v���Z�X�u���v�́A�R�}���h�̌��ʂ� �t�@�C���̓��͂̂悤�Ɉ������� �o�͂��R�}���h�ɓn������ł��܂��B

<(�R�}���h)

�܂��� "<(�R�}���h)" �̕��ł����A�R�}���h�œ��̓t�@�C���̃p�X�� �w�肷��Ƃ���ɏ������Ƃ��ł��܂��B

�悭�g�����Ƃ��Ă� diff �R�}���h�ł��B
diff �R�}���h�́A2�‚̃t�@�C�����r����ۂ� �W���o�͂� 1�‚����w��ł��Ȃ����� 2�‚̃R�}���h�̎��s���ʂ��r�������ꍇ ��r����R�}���h�̕Е��͎��̂��K�v�ɂȂ�܂��B

$ ls -l /var/xxxx > xxxx.txt
$ ls -l /var/yyyy > yyyy.txt
$ diff xxxx.txt yyyy.txt
$ ls -l /var/xxxx > xxxx.txt
$ ls -l /var/yyyy | diff - xxxx.txt

�u�v���Z�X�u���v���g���� �ꎞ�t�@�C�����쐬������ 2�‚̃R�}���h�̎��s���ʂ� ���̂܂ܔ�r���邱�Ƃ��ł��܂��B

$ diff <(ls -l /var/xxxx) <(ls -l /var/yyyy)

�R�}���h�����₷���ł��ˁB
�ꎞ�t�@�C�����폜�����Ԃ��Ȃ��Ȃ�܂��B

echo �ŏo�͂���� �u�v���Z�X�u���v�̎��̂� �t�@�C���f�X�N���v�^���Ƃ킩��܂��B

$ echo <(echo 1)

/dev/fd/63

�킩��ɂ����Ȃ�܂��� ���̂悤�Ȃ��Ƃ��ł��܂��B

$ $(cat <(echo date))

Thu Dec  8 22:14:36 JST 2018

����� �܂� ���̂悤�ɏ�������� "date" ���Ԃ��Ă��܂��B

$ echo date > /dev/fd/63
$ cat /dev/fd/63

�Ԃ��Ă��� date �����s���� �������o�͂���܂����B

$ date

Thu Dec  8 22:14:36 JST 2018

�܂� ���̂悤�� do ... done �̃��[�v�� �p�C�v�ł‚Ȃ��� ���̏������ʃv���Z�X�ɂȂ� �‹��ϐ��� �㏑�����Ă���Ȃ��悤�ȏꍇ�A�A�A

$ filename=none

$ ls | grep -v "test." | while read filepath
> do
>     filename=$(basename $filepath)
> done

$ echo $filename

none   #���ʃv���Z�X�̂��ߏ㏑������Ȃ�

�u�v���Z�X�u���v���g���� �t�@�C�����w�肷��̂Ɠ����悤�� �����v���Z�X�ŏ������邱�Ƃ��ł��܂��B

$ filename=none

$ while read filepath
> do
>     filename=$(basename $filepath)
> done < <(ls | grep -v "test.")

$ echo $filename

xxxxx.txt   #�������v���Z�X�̂��ߏ㏑�����ꂽ

>(�R�}���h)

���� ">(�R�}���h)" �̕��ł����A������� ���������p�C�v�łł��Ă��܂����� ���܂�ǂ��Ⴊ�v�������т܂���ł����B

�悭�g���͎̂��̂悤�� �W���G���[�o�͂� �s�v�ȍs���I�~�b�g����P�[�X���ł��B

$ command 2> >(grep -v ^Notice: >&2)

����́A�W���G���[�o�͂���U �v���Z�X�u���� grep �R�}���h�ɓn���� "Notice:" ���� �n�܂�s���Ȃ��āA�ēx�W���G���[�o�͂ɓn���Ă��܂��B

���ɂ� tee �R�}���h�Ƒg�ݍ��킹�� ����̏o�͂����U�蕪���� �Ȃ�Ă��Ƃ��ł��܂��B

$ cat test.txt | \
>    tee >(grep ^case1 > case1.txt) \
>    tee >(grep ^case2 > case2.txt) \
>    tee >(grep ^case3 > case3.txt) \
>    > /dev/null

���̗�ł́A�o�͂��ꂽ�s�̐擪�̕����ɂ���� �ʂ̃t�@�C���ɕۑ����Ă��܂��B

Google �T�C�g������

Amazon�A�\�V�G�C�g