Environment Variables
Environment Variables
Here is a typical variable declaration at the beginning of a SlackBuilds.org script: PRGNAM=some_program_name VERSION=1.0.0 ARCH=${ARCH:-i486} BUILD=${BUILD:-1} TAG=${TAG:-_SBo} CWD=$(pwd) TMP=${TMP:-/tmp/SBo} PKG=$TMP/package-$PRGNAM OUTPUT=${OUTPUT:-/tmp} The syntax of ${TMP:-/tmp/SBo} means that if the $TMP variable exists in the parent environment then use that value otherwise assign the value of the variable to (in this case) /tmp/SBo. Assigning a value to $TMP in one of several places is straightforward (~/.bashrc, /etc/bashrc, /etc/profile.d, etc.). I would like to assign the OUTPUT variable to $CWD. Yet $CWD is unknown to the parent environment and unknown until I run the build script. I can: 1. Manually edit the script to OUTPUT=$CWD. 2. Start the script with OUTPUT=$(pwd) sh buildscript I would never remember option 2 all the time. Therefore I always edit build scripts with option 1. I've been doing that for a long time, but I wonder whether a more clever method exists so could run these scripts as is without manually editing. Is there a way to programmatically assign OUTPUT globally so all I need do is change to the build directory and type sh buildscript? |
Quote:
Quote:
|
Maybe alias will help you too. Add this to your ~/.bashrc:
Code:
alias shslkbd='OUTPUT=$(pwd) sh' |
Well, we're on the same page anyway. :) I too thought about a script, a function, and an alias.
|
All times are GMT -5. The time now is 09:03 PM. |