I don't understand why this simple read doesn't work. Mind you, I am VERY new to bash. :)
#!/bin/bash
echo -n "Project Name: "
read PROJECT_NAME
if [ -n "$PROJECT_NAME" ]; then
echo "You must provide a project name."
exit 2
fi
-- snip --
When this executes, it asks for the project name. After I press enter, I get "You must provide a project name." and then the scripts exists instead of continuing.
What am I doing wrong?
Thanks Eric
You want [ -z "$PROJECT_NAME" ], not -n:
From man test:
-n STRING
the length of STRING is nonzero
...
-z STRING
the length of STRING is zero
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With