PDA

View Full Version : Help in Scripting



Mohan1289
October 22nd, 2012, 08:41 AM
How can we check weather the directory is created or not in shell script???

i mean if i write

mkdir dirname

and if i have to run the script continuously

is there a way to check weather the directory exists or not???

can we do that?

steeldriver
October 22nd, 2012, 09:00 AM
You can either check the exit status of the mkdir command directly


mkdir "$dir" || do somethingor by using the built-in exit status variable $?


mkdir "$dir"
if [ $? -ne 0 ]; then ...or test the directory existence with the -d file test


if [ -d "$dir" ]; then ...Just some ideas

Mohan1289
October 22nd, 2012, 09:02 AM
You can either check the exit status of the mkdir command directly


mkdir "$dir" || do somethingor by using the built-in exit status variable $?


mkdir "$dir"
if [ $? -ne 0 ]; then ...or test the directory existence with the -d file test


if [ -d "$dir" ]; then ...Just some ideas

Thank you