Ad

Get Folder Name With Find ... -name Command In Bash

- 1 answer

Trying to get name of venv folder for activating it in bash script located inside the project. Because someone could use for venv another name like 'someones_env'

projectdir=$(cd ../../ && pwd)
echo "$(dirname "$projectdir")"

venvdir=$(find "$(dirname "$projectdir")" -name '*env')
echo "$(dirname "$venvdir")"

source "$(dirname "$venvdir")"/bin/activate

but $venvdir becomes the same as $projectdir instead of 'someones_env'

what am i doing wrong? thanks

Ad

Answer

The directory of the *env folder is the project directory, that's why dirname "$venvdir" becomes the same as the project directory. Without dirname it should work.

Also, the directory of ../../ is ../../../, this might also be giving you some issues. If you are already in a directory, there's no need to use dirname. dirname calculates the parent directory.

Ad
source: stackoverflow.com
Ad