1

I'm a bit of a noob with Perl, and can't to see what's wrong with this script:

#!/bin/sh
randAnPass=true;
if [ $randAnPass = true ]
then
pass=perl /root/bin/randpass
else
# prompt for setting user's password ..
echo -n "pick password for '${user}': "
read pass
fi
#echo $randAnPass;
echo "Generated pass = $pass";

For some reason it outputs:

r4Nd0mP
Generated pass = 

I want it to output

Generated pass = r4Nd0mP
Jens
  • 69,818
  • 15
  • 125
  • 179
Goulash
  • 3,708
  • 6
  • 29
  • 48

2 Answers2

5

If you want to just capture STDOUT of perl command use,

pass=$(perl /root/bin/randpass)

But if you need to capture both STDERR and STDOUT,

pass=$(perl /root/bin/randpass 2>&1)
Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187
4
pass=`perl /root/bin/randpass`
DVK
  • 126,886
  • 32
  • 213
  • 327