Why i not getting echo "User password is= $typo"
result
How i can get result of typo in the end after while loop.
#!/bin/sh
pass_mes()
{
read -sp 'Password: ' passvar
echo $passvar
}
password_verify()
{
pass_ver=$(dscl /Search -authonly skull $typo 2>&1 | grep -i Authentication | awk '{print $1$5}')
if [ "$pass_ver" == "Authenticationfailed." ]; then
echo "Wrong_Password"
else
echo "Correct_Password"
fi
}
funtion_cancle()
{
us_output=$(pass_mes)
if [ "$us_output" == "User_Cancel" ]; then
echo "User_Cancel"
else
echo "$us_output"
fi
}
funtion_final_output()
{
typo=$(funtion_cancle)
if [ "$typo" == "User_Cancel" ]; then
echo "User_Cancel"
elif [ -z $typo ]; then
echo "empty"
else
if [ "$(password_verify)" == "Correct_Password" ]; then
echo "WORKING_SKULL"
else
#echo "Wrong_Password"
echo "NOT_WORKING_SKULL"
fi
fi
}
retry_funtion()
{
echo "****Wrong Password Typed****"
}
cancel_funtion()
{
echo "***User Cancled ***"
}
############## Script start ##################
echo "Script start"
while :
do
case $(funtion_final_output) in
"NOT_WORKING_SKULL") retry_funtion
;;
"empty") retry_funtion
;;
"User_Cancel") cancel_funtion exit
;;
"WORKING_SKULL") break
;;
esac
done
echo "User password is= $typo"
echo "Continue script using password $typo"
As people said before, parts of your script running in sub-shells, so
$typo
is lost.Try this, it works:
In my solution, run
while
loop passingfuntion_final_output
arguments to it like:while ... do ... done < <(echo $(funtion_final_output))
To be able to pass values, you must not just
echo
them in functions, but assign it to variables (part offuntion_final_output
:)Was:
Now:
I've made variables assignments like that in each
if
infuntion_final_output
)Next, when you pass variables in the final
loop
, you must read them.while :
rewritten towhile read -r ret typo
Enjoy.
You are assinging typo like a local variable. In the main body of your script, the "typo variable was unset".
By other way, I don't understand the pourpose of the "funtion_cancle()" function. If the "us_output" variable is "User_Cancel" you return "User_Cancel", else if "us_output" is "a_valid_pass" you return the same...This function doesn't do anything
I recommend you make this:
An example: