0
#!/bin/sh
#myVar=`date`#case 1
#myVar=`cat /dev/stdin`#case 2
myVar=($(< /dev/stdin)) #case 3
echo $myVar
exit 2

case 1 works case 2 and 3 don't work. When I test with either 2 or 3; there is no output and the script never exits

What I eventually require is to read from the stdin written to by the postfix pipe

2
  • 2
    Calling a script with /bin/sh does not make it a bash script.
    – adaptr
    Nov 2, 2012 at 12:55
  • Please fix your question to be more specific about what you are asking. Nov 6, 2021 at 15:00

1 Answer 1

1
#!/bin/bash
read fred
echo $fred
4
  • I want to read multiple lines !
    – Stewie
    Nov 1, 2012 at 20:46
  • 2
    You should probably have said so, then. Do you want to read them to one variable, or many? More precision in the question will get you more functionality in the answers!
    – MadHatter
    Nov 1, 2012 at 21:11
  • 2
    @Stewie while read line ; do echo $line ; done
    – ott--
    Nov 2, 2012 at 13:10
  • @MadHatter I had written that "What I eventually require is to read from the stdin written to by the postfix pipe" which would explain that the data will span multiple lines, but I guess it wasn't enough and I'll take care next time :) Anyway initializing as bin/bash instead of bin/sh solved it thanks
    – Stewie
    Nov 2, 2012 at 13:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .