When using pipe with or without global g option gives same result:
echo -e 'hi\nhello\nhi' | sed '1s/hi/hey/g'
hey
hello
hi
works for here-string as well when not using global g option:
sed '1s/hi/hey/' <<< $(echo -e 'hi\nhello\nhi')
hey hello hi
but when using global g option and here-string replaces the pattern at every line:
sed '1s/hi/hey/g' <<< $(echo -e 'hi\nhello\nhi')
hey hello hey
Why this change in the output when using the global substitution flag and when input comes through here-string?