This command does not store the token on the variable. The variable becomes empty. TOKEN=$(./login.sh $DSPACEURL ${EMAIL} ${PASSWORD} $VERSION) Then, I've used this instead: ./login.sh $DSPACEURL ${EMAIL} ${PASSWORD} $VERSION 2> ./token.txt TOKEN=$(cat token.txt | grep JSESSIONID | cut -f2 -d "=" | cut -f1 -d ";")