Home > Software design >  get folder name with find ... -name command in bash
get folder name with find ... -name command in bash

Time:02-04

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

CodePudding user response:

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.

  •  Tags:  
  • Related