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
  • 65,924
  • 14
  • 115
  • 171
Goulash
  • 3,338
  • 6
  • 26
  • 44

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
  • 54,465
  • 14
  • 131
  • 183
4
pass=`perl /root/bin/randpass`
DVK
  • 123,561
  • 31
  • 206
  • 320