I am having a problem with the condition of the second if statement [ -z "$(ls -A $workdir)" ] if the workdir path has space in it. I tried to enclose it with "$workdir" but not working. I appreciate your help.
#!/bin/bash
workdir=${1:-$(pwd)}
if [ -d "$workdir" ]; then
    if [ -z "$(ls -A $workdir)" ]; then
        echo "Working directory is set to: $workdir"
    else
        echo "Working directory is not empty!"
        read -p "Do you want to continue? (y/n) " choice
        if [[ "$choice" == [yY] ]]; then
            echo "Continuing..."
        elif [[ "$choice" == [nN] ]]; then
            echo "Exiting."
            exit 0
        else
            echo "Invalid choice. Please enter y or n."
            exit 1
        fi
    fi
else
    echo "Creating and setting as working directory: $workdir"
    mkdir -p "$workdir"
fi
mkdir -p "${workdir}"/{code,data,docs,logs,outs,temp}
mkdir -p "${workdir}/code/utils"
mkdir -p "${workdir}/data/{raw,processed}"
I need a way to include paths that have empty strings in the above code without raising errors.
 
    