Need to translate windows command to bash script

Viewed 50

I need to translate the following windows command to bash:

echo %BUCKET%
cd %script_folder%
if not exist "venv" (virtualenv -p C:\Python37\python.exe venv)
cd venv\Scripts\
call activate
cd ..\..\
pip install -r requirements.txt
pause

What I came with was:

echo %BUCKET%
cd %script_folder%
   #if not exist "venv" (virtualenv -p C:\Python37\python.exe venv) -- How?
cd venv/Scripts/
   #call activate -- How?
cd ../../
pip install -r requirements.txt | less

I am not sure the conversion is correct and in any case I do not know how to convert the "How?" labeled rows.

2 Answers
echo $BUCKET
cd $script_folder

if [ ! -d venv ]; then
    python3 -m venv venv
fi

source venv/bin/activate
python3 -m pip install -r requirements.txt | less

You can do something like that:

#!/bin/bash
echo "$BUCKET"
cd "$script_folder"
[ ! -d venv ] && python3 -m venv venv
bash --init-file <(echo ". venv/bin/activate; pip install -r requirements.txt;")

Don't forget to make it executable:

chmod +x thescript.sh
Related