Friday afternoon headache

Hi all,

It's been a long week and my brain is clearly not functioning right so hopefully someone can help me out here.

I've got a function in a script which just checks if a MySQL database directory exists or not. Code is as follows:

dbCheck2() {
if [ -d '/var/lib/mysql/$IPdb' ];
then {
	:
             # carry on in parent script
}
else {
	echo "No Valid Database specified. Please try again."
	some_other_function
}
fi
}

For arguments sake let the variable IPdb = test as this value is coming from another function. Now even when the directory /var/lib/mysql/test exists it still displays the else statement.

Can someone put me out of my misery and tell me what's wrong?

Thanks!

i am new to unix world so i am not sure my advice will be useful or work... i am just studyind test command now....
try:

dbCheck2()
{if
[ -d /var/lib/mysql/$IPdb ]
echo hi #just to check if it goes through first if
then :
# carry on in parent script
else
echo "No Valid Database specified. Please try again."
some_other_function
fi
}

I REPEAT: maybe it wont work but who knows....

you are passing the "/var/lib/mysql/$IPdb" as a String rather than a directory

so your code should be

dbCheck2() {
if [ -d /var/lib/mysql/$IPdb ];
then {
	:
             # carry on in parent script
}
else {
	echo "No Valid Database specified. Please try again."
	some_other_function
}
fi
}
if [ -d '/var/lib/mysql/$IPdb' ];

Inside single quotes shell variable $IPdb wont expand.

Use this

if [ -d "/var/lib/mysql/$IPdb" ];

Hi,

Thanks, both using no quotes and double quotes worked.