Bashing Missing Directories

dynamic-python-developer
Dynamic Python
Published in
2 min readFeb 25, 2021

--

As a skilled full-stack developer I sometimes find myself needing to code some bash to make my CI/CD work until I run into some directories that do not exist.

Photo by Javardh on Unsplash

Shell programming can be quite a joy especially when you can do it on the beach which I cannot.

The typical code, shown below, should work until it fails. I am not sure why this code is failing and I do not care why it is failing so I coded a fix.

For the record, this is happening with Ubuntu 20.04 (latest) which I am running via WSL2 in Windows 10.

Also for the record, this was not an issue until recently and today I get to fix it. Oooh, la la.

Here’s the code:

if [[ -d "$vyperlib" ]]
then
echo "$vyperlib exists"
else
echo "$vyperlib does not exist"
fi

Fails with a “permission denied” I am guessing because the missing directory has the wrong permissions. Duh!

This is the code that solves the problem:

VENV=$dir1/.venv

python=/usr/bin/python3.9
vers=$($python -c 'import sys; i=sys.version_info; print("{}{}{}".format(i.major,i.minor,i.micro))')
VENVvers=$(ls $VENV$vers)

if [ -z "$VENVvers" ]
then
ENVS=$(ls -d .venv*)
for val in $ENVS; do
echo "Removing $val"
rm -R -f $val
done
virtualenv --python $python -v $VENV$vers

--

--

dynamic-python-developer
Dynamic Python

Dynamic Pluggable MicroService Framework v3.1 now in Production !!! (raychorn.github.io)