0

I'm trying to automate my chromium dev setup. I have a script to check if depot_tools exists in the pwd - if not download and add to path. It works on the command line but not in the bash script:

export PATH=$PATH:$PWD/depot_tools

I'm using Ubuntu 20 if that helps.

nw.sh:

#!/bin/bash

DEPOT_TOOLS=depot_tools

if [ ! -d "${DEPOT_TOOLS}" ]; then
        echo "[ WARN ] ${DEPOT_TOOLS} does not exist."
        echo "[ INFO ] Downloading ${DEPOT_TOOLS}..."
        git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
else
        echo "[ INFO ] ${DEPOT_TOOLS} already exists."
        echo "[ INFO ] Adding ${DEPOT_TOOLS} to end of PATH..."
        export PATH="$PATH:$PWD/${DEPOT_TOOLS}"
fi
Ayush C.
  • 19
  • 1
  • 7
  • Rather than cloning to whatever your current directory is, clone to a *fixed* location, then ensure that that location is in your path. – chepner Oct 19 '22 at 18:46
  • 2
    A process can't modify the environment of its parent process; so if you're literally running this as an executable script, then `export PATH="$PATH:$PWD/${DEPOT_TOOLS}"` won't have any effect. – ruakh Oct 19 '22 at 18:47
  • please update the question with more details on what you mean by `*it fails*` ... error? wrong path added to `PATH`? nothing added to `PATH` (and if so, how/where are you checking ... in the same script, in a subscript, after exiting the script)? – markp-fuso Oct 19 '22 at 18:50
  • @chepner Did that initially and it worked. Question was to use `pwd` instead. @markp-fuso Found my answer via @ruakh's comment – Ayush C. Oct 19 '22 at 18:57

0 Answers0