05-02-2024, 01:01 PM
I am currently working on a shell script in ksh on an AIX system. The goal is to create a directory that may or may not already exist. Using the `mkdir` command directly is not feasible because it throws an error when the directory exists. I'm looking for a way to check if the directory doesn't exist before attempting to create it, or a method to suppress the error that mkdir throws when it runs into an existing directory.
A straightforward approach is to use the `if` statement to check for the directory's existence before using `mkdir`. Here's what I've attempted so far:
However, I'm unsure if this is the best practice for handling this situation in ksh. Could there be a more efficient or cleaner way to accomplish this task?
A straightforward approach is to use the `if` statement to check for the directory's existence before using `mkdir`. Here's what I've attempted so far:
Code:
then
mkdir "/path/to/mydir"
fi
However, I'm unsure if this is the best practice for handling this situation in ksh. Could there be a more efficient or cleaner way to accomplish this task?