LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Environment Variables (https://www.linuxquestions.org/questions/slackware-14/environment-variables-693177/)

Woodsman 12-26-2008 08:45 PM

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?

saulgoode 12-26-2008 11:15 PM

Quote:

Originally Posted by Woodsman (Post 3388121)
Is there a way to programmatically assign OUTPUT globally so all I need do is change to the build directory and type sh buildscript?

You could create a simple script especially for executing slackbuilds with your environment settings (and based on the current directory at time of invocation).

Quote:

#!/usr/bin/bash
ARCH=i686
OUTPUT=$(pwd)
sh $1

grissiom 12-27-2008 12:07 AM

Maybe alias will help you too. Add this to your ~/.bashrc:
Code:

alias shslkbd='OUTPUT=$(pwd) sh'

Woodsman 12-27-2008 01:49 PM

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.