B
B
BonBon Slick2020-07-31 16:37:51
linux
BonBon Slick, 2020-07-31 16:37:51

How to access global variables in shell script?

#!/bin/bash
 
cd ../
rm -R --force dist/
npm install
cordova platform rm android
cordova platform add android
cordova prepare
cordova clean
cordova build android
$ANDROID_HOME/tools/bin/sdkmanager --licenses

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Koryukov, 2020-07-31
@BonBonSlick

It's called Environment Variables.
It is important how and where you set them. You can view the list of environment variables in the current sh process by executing the command
env
. Environment variables are usually passed to programs and scripts that you run.
If you want to set a variable so that it is passed when the program starts, it must be exported

ANDROID_HOME=/home/user/android
export ANDROID_HOME

these lines can be executed in the terminal and then the variable will exist in this terminal until it is closed. Or you can paste these lines into ~/.bashrc so that they are executed every time the terminal is started.
Or, if you need to pass a variable to the script once, you can specify it at startup, like this
ANDROID_HOME=/home/user/android ./script.sh
. If the script is launched not in the terminal, but, for example, through an IDE or in a CI / CD system, then you need to read the documentation for it, it is most likely described there as set environment variables.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question