此问题已在此处有答案:
Test whether a glob has any matches in Bash(22答案)
2天前关闭。
如果workdir路径中有空间,我在第二个if语句[ -z "$(ls -A $workdir)" ]
的条件下遇到问题。我试图用“$workdir”将其括起来,但不起作用。感谢您的帮助。
#!/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}"
我需要一种方法来包括上述代码中包含空字符串的路径,而不会引发错误。
1条答案
按热度按时间fd3cxomn1#