This question already has an answer here:
So I've got a shell script to do some lazy stuff for if the directory isn't changing for a user. It's below. Essentially, it should be an if statement that if the user enters "default" for the directory, it'll pull them to the default directory for the files. However, I'm getting a command not found
on line 16, which is the reassignment statement.
The entire if
statement below:
if [ $directory = "default" ];
then
echo Enter your ldap:
read $ldap
$directory = "/usr/local/home/google/${ldap}/Downloads"
fi
I've tried doing it without the dollar sign too...nothing. What's going on here? New to shell, couldn't find this question asked before either.
This is how you should assign a value to a variable in shell:
$
) sign.=
) sign.Also, you should wrap your variables inside double quotes (
"
). This way, you avoid errors with undefined variables, arguments with spaces, etc.That gives us: