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
7
  • 1
    Use backticks to capture command output, you're just running the command. Commented Feb 26, 2012 at 1:30
  • 1
    @Dave: Backticks? $() is much better. Commented Feb 26, 2012 at 1:32
  • I don't see how it can be much better, but sure, that works too. Commented Feb 26, 2012 at 1:32
  • That worked :D probably should've been an answer lol cause.. well it is the answer :P. Thanks very much. :) Commented Feb 26, 2012 at 1:33
  • @DaveNewton - I am not sure of the benefits, so I asked :) stackoverflow.com/questions/9449778/… Commented Feb 26, 2012 at 1:38

2 Answers 2

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)
Sign up to request clarification or add additional context in comments.

Comments

4
pass=`perl /root/bin/randpass`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.