Sponsored Content
Top Forums UNIX for Advanced & Expert Users Setting global variables with BASH/Linux Post 302260329 by gregf on Thursday 20th of November 2008 08:44:24 AM
Old 11-20-2008
Setting global variables with BASH/Linux

I am using functions in a script and for some strange reason the EXPORT command doesnt seem to be making my variables global.

Anyone got any ideas?

I am using one function to pass some output top another using the pipe command, eg

Function 1 | Function 2

Function 2 reads the value passed from Function one and sets some variables based on its value then exports them

setStartSeq() {
read logFile
echo "Start redo log: $logFile"
arcPrefix=$(echo $logFile | cut -d_ -f1)"_"$(echo $logFile | cut -d_ -f2)
startSeq=$(echo $logFile | cut -d_ -f3 | cut -d. -f1)
export arcPrefix=$arcPrefix
export startSeq=$startSeq
}


Yet later on in the script another function tries to use the above exported variables and they arent set!!

I have confirmed that by running an export -p in the later function and all values set above are blank.

I am new to BASH and Linux but have used export without issue with kornshell.


Any help would be greatly appreciated Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Global PATH setting

I am using Solaris 8 and I want to change the PATH setting for all users. I have edited /etc/profile, but when I log in and check the PATH variable, it hasn't changed. Am I missing something? (5 Replies)
Discussion started by: jxh
5 Replies

2. UNIX for Dummies Questions & Answers

setting global variable for all users

hi, i am a newbie unix administrator. i want to set a variable, let's say : alias cls 'clear' But i am not going to add this line in the .login file for every home directory of my 500+ users. pls tell me where should i put this line in, so that all users can use this variable after... (4 Replies)
Discussion started by: champion
4 Replies

3. Shell Programming and Scripting

perl global variables

Can someone give me "the lecture" on why you shouldn't make all your varables global when programming in perl. I have been doing this but I have heard that it is not a good practice. (3 Replies)
Discussion started by: reggiej
3 Replies

4. UNIX for Dummies Questions & Answers

setting a global variable in script

Hi All, I know to set global variable i can use export .. But take the situation like below .. I want to set a variable in one script and access that in second script i have done like this .. It is not working one.sh #!/usr/bin/ksh echo $RISSHI export RISSHI=1 two.sh... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

5. UNIX for Dummies Questions & Answers

global variables

Hi, I hav created a script that calls a sub-script. In both the scripts i called the configuration file. Now i wanted to use a variable that should be used in both script and sub-script files. Actually, i wanted to return a file name and the return status to the script file from the sub-script.... (6 Replies)
Discussion started by: Swapna173
6 Replies

6. Solaris

How to access ENV variables of non global zones in global zone???

Hi Guys, My requirement is I have file called /opt/orahome/.profile in non global zone. PATH=/usr/bin:/usr/ucb:/etc:/usr/sbin:/usr/local/bin:/usr/openwin/bin:. export PATH PS1="\${ORACLE_SID}:`hostname`:\$PWD$ " export PS1 EDITOR=vi export EDITOR ENV=/opt/orahome/.kshrc export ENV... (1 Reply)
Discussion started by: vijaysachin
1 Replies

7. UNIX for Advanced & Expert Users

Setting a permanent global variable in unix accessible from any script

Is there anyway in which i can set a permanent global variable in unix, which when initialised with a value and modified during any shell script, would retain its value even if i logout and login I dont know whether i am being able to express my need clearly but basically what i want is a... (3 Replies)
Discussion started by: arindamlive
3 Replies

8. UNIX for Dummies Questions & Answers

Global variables in perl

hi all, i need a help for the following query. Thanks in advance for your valuable time. i have a main.pl file which has a global variable declared as below. our myVar=0; call first.pl script from the main.pl script. print the value of myVar (the value is still 0 and not 10.) i have a... (1 Reply)
Discussion started by: hemalathak10
1 Replies

9. Shell Programming and Scripting

'Dynamic' setting of variables in bash script

Hi all, I want to dynamically set variables in a bash script. I made a naive attempt in a while loop that hopefully can clarify the idea. n=0; echo "$lst" | while read p; do n=$(($n+1)); p"$n"="$p"; done The error message is: bash: p1=line1: command not found bash: p2=line2: command... (8 Replies)
Discussion started by: jeppe83
8 Replies

10. Shell Programming and Scripting

Bash: Setting default values for variables

I have a variable I want to use in bash script. The user will pass an argument to the script and I will store it in `arg_fql`. If the user does not pass the variable, I still never set arg_fql, but I set another variable to a default. However, if the user passes a value, `arg_fql` will be set to... (2 Replies)
Discussion started by: kristinu
2 Replies
STOREBACKUPUPDATEBACKUP(1)				User Contributed Perl Documentation				STOREBACKUPUPDATEBACKUP(1)

NAME
storeBackupUpdateBackup.pl - updates / finalizes backups created by storeBackup.pl with option --lateLink, --lateCompress SYNOPSIS
storeBackupUpdateBackup.pl -b backupDirectory [--autorepair] [--print] [--verbose] [--debug] [--lockFile] [--noCompress] [--progressReport number] [--checkOnly] [--logFile [--suppressTime] [-m maxFilelen] [[-n noOfOldFiles] | [--saveLogs]] [--compressWith compressprog]] storeBackupUpdateBackup.pl --interactive --backupDir topLevlDir [--autorepair] [--print] WARNING
!!! USAGE IN PARALLEL WITH storeBackup.pl CAN DESTROY YOUR BACKUPS !!! OPTIONS
--interactive, -i interactive mode for reparing / deleting currupted backups created with option '--lateLinks' --backupDir, -b top level directory of all backups (must exist) --autorepair, -a repair simple inconsistencies automatically without requesting the action --print print configuration read from configuration file and stop --verbose, -v verbose messages --debug, -d generate detailed information about the files with the linking information in it --lockFile, -L lock file, if exist, new instances will finish if an old is already running If set to the same file as in storeBackup it will prevent $prog from running in parallel to storeBackup, default is $lockFile --noCompress maximal number of parallel compress operations, default = chosen automatically --checkOnly -c do not perform any action, only check consistency --progressReport print progress report: after each 'number' files when compressing after each 'number * 1000' files when linking after each 'number * 10000' files when performing chmod --logFile, -l logFile, Default: stdout --suppressTime suppress output of time in logfile --maxFilelen, -m maximal length of log file, default = 1e6 --noOfOldFiles, -n number of old log files, default = 5 --saveLogs save log files with date and time instead of deleting the old (with [-noOldFiles]) --compressWith compress saved log files (e.g. with 'gzip -9'). default is 'bzip2' COPYRIGHT
Copyright (c) 2008,2012 by Heinz-Josef Claes. Published under the GNU General Public License v3 or any later version perl v5.14.2 2012-06-16 STOREBACKUPUPDATEBACKUP(1)
All times are GMT -4. The time now is 08:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy