1
#!/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

  • 1
    Calling a script with /bin/sh does not make it a bash script. – adaptr Nov 2 '12 at 12:55
1
#!/bin/bash
read fred
echo $fred
  • I want to read multiple lines ! – Stewie Nov 1 '12 at 20:46
  • 1
    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 '12 at 21:11
  • 1
    @Stewie while read line ; do echo $line ; done – ott-- Nov 2 '12 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 '12 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.