git - Piping functions with other commands in linux -


i pipe function normal commands in linux. please note these commands put .sh script (i use bash shell). example, have me command follows:

git diff --name-only head~1..head -z | xargs -0 dirname | catch_exceptions >> extracted_dir_names

i have written catch_exceptions function above command , contains 2 sed delete statements. if pipe 2 sed commands in function work if put them 1 after other don't. explain why , how work around can done? in advance.

this works:

function catch_exceptions {      sed '/^\./d' | sed '\#this/path/alone#d' }  pushd /path/to/direc rm -f extracted_directories.txt git diff --name-only head~1..head -z | xargs -0 dirname | remove_duplicates | catch_exceptions >> extracted_directories.txt cat extracted_directories.txt popd } 

but when replace catch_exceptions with:

function catch_exceptions {     sed '/^\./d'      sed '\#this/path/alone#d' } 

it doesn't work.

with first function, output of first sed command fed second, when first completes, second too.

with second function, output of first sed sent direct standard output, , when finishes second sed start. second sed has standard input still connected pipe, first 1 read data, second sed gets nothing process.

if want both sed commands read same pipe, review two children reading pipe, , consider using tee process substitution. review redirect stdout of 1 process 2 processes.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -