LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 12-26-2008, 08:45 PM   #1
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
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?
 
Old 12-26-2008, 11:15 PM   #2
saulgoode
Member
 
Registered: May 2007
Distribution: Slackware
Posts: 288

Rep: Reputation: 155Reputation: 155
Quote:
Originally Posted by Woodsman View Post
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
 
Old 12-27-2008, 12:07 AM   #3
grissiom
Member
 
Registered: Apr 2008
Location: China, Beijing
Distribution: Slackware
Posts: 423

Rep: Reputation: 45
Maybe alias will help you too. Add this to your ~/.bashrc:
Code:
alias shslkbd='OUTPUT=$(pwd) sh'
 
Old 12-27-2008, 01:49 PM   #4
Woodsman
Senior Member
 
Registered: Oct 2005
Distribution: Slackware 14.1
Posts: 3,482

Original Poster
Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
Well, we're on the same page anyway. I too thought about a script, a function, and an alias.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Environment variables Sunfist Linux - Newbie 1 05-17-2008 06:05 PM
when to use environment variables? mark_2811 Programming 2 02-23-2004 06:09 PM
environment variables moeminhtun Linux - General 4 01-15-2003 09:50 AM
environment variables da Perp Linux - Newbie 5 01-23-2002 09:34 AM
environment variables aethereal Linux - Newbie 7 12-19-2001 09:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 07:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration