0

I am trying to install zfs through shell script while installation I am getting some error so, to automate it fully, I want to get the version to be installed from error itself. For all other commands I am getting the error in one variable but for one command its not coming at all. I tried every solution possible.

I need output of this command

sploutput=$(sudo dkms install -m spl -v $version)

echo $sploutput

echo $sploutput # This is giving nothing.

I tried wrapping it around string also like "sploutput=$(sudo dkms install -m spl -v $version)"

echo "{sploutput}"

Nothing seems to work.

2 Answers 2

1
sploutput=$(sudo dkms install -m spl -v $version)
echo $sploutput

it might be because the dkms install outputs on STDERR and not on STDOUT, and with the command you're using, you're only getting STDOUT output in the variable. To take both, you can try:

sploutput=$(sudo dkms install -m spl -v $version 2>&1)

to redirect STDERR into STDOUT.

Sign up to request clarification or add additional context in comments.

Comments

1

As per ZMO's answer: try running sudo dkms install -m spl -v $version

See, what is it returning? : STDERR or STDOUT.

In case, if it fails, it won't show up anything in sploutput. It write only STDOUT to the variable.

Use 2>&1(to write Standard error to standard output). You can refer IO redirection

You can use following:

sploutput=$(sudo dkms install -m spl -v $version 2>&1)
echo $sploutput

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.