I'm in the process of understanding shell scripting - this is my simple code for adding test files for python unittest
I'm looking for best practice pointers, variable naming, and of course comments on structure and readability.
EDIT: Script is called by, for example
./create_tests.sh math tensor_add
dir_name="$1"
file_name="$2"
test_dir="test/${dir_name}"
file_in_dir="${test_dir}/${file_name}.py"
addFile() {
if [[ -f "${file_in_dir}" ]]
then
echo "File already exists in directory, exiting."
exit 0
else
touch "${file_in_dir}"
fi
}
if [[ -d "${test_dir}" ]]
then
echo "Directory already exists, adding the file to this directory."
addFile
else
echo "Directory and __init__.py created."
mkdir "${test_dir}"
touch "${test_dir}/__init__.py"
addFile
fi