0

I want to check my script with exit codes.

        sudo groupmod -n $newname $name 
        sudo usermod -l $newname --move-home --home /home/$newname $name 
        let $exitcode=$?
        echo $exitcode
            if [ "$exitcode" = 0 ]  
            then   
                echo "Everything's ok"
                exit
            elif [ "$exitcode" != 0 ]
            then
                echo "Try again"
                exit 
            fi

Here is wath I get :

  let :=0 :Syntax error :operand expected (error is "=0")

I don't get it. I use the shell buit-in keyword let.

1

I've made this correction:

let exitcode=$? and not let $exitcode=$?

That fixes the syntax error.

| improve this answer | |
  • Oh sorry, I misunderstood you then. I thought the question was still relevant after this fix. – egmont Jul 29 '19 at 11:09

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.