Sponsored Content
Top Forums Shell Programming and Scripting functions and variables in bash Post 302699427 by kristinu on Tuesday 11th of September 2012 03:39:28 PM
Old 09-11-2012
functions and variables in bash

I have a bash script with some functions as below and am wondering if I can use the variables declared in setup in the other functions and in the rest of the bash script.

Code:
setup(){

  none=0; low=1; medium=2; high=3; debug=4

  var1="red"
  var2="fred"

}

create_basemap() {
   
 xminBse=$(( $xmin - 2.0 ))   
 xmaxBse=$(( $xmax + 2.0 ))   
 zminBse=$(( $zmin - 2.0 ))     
 zmaxBse=$(( $zmax + 2.0 )) 
  
 xpos=0   
 ypos=0   
 xpos=$xmin   
 ypos=$(( $zmax + 1.5 ))   
 title="Sound speed, c, Mm/min"   
 xDesc="Distance, x, Mm"   
 yDesc="Depth, z, Mm" 
  
 # Scale attributes   xpos=$(( $wtimap + 0.5 ))    
 ypos=$(( $htimap / 2.0 ))   
 sclen=$htimap   scwid=0.4   

 # Create the grid   
 xyz2grd $f.xzc -G$f.grd -I$vdx/$vdz -R$xmin/$xmax/$zmin/$zmax   # Create the color palette   makecpt -C$color -T$cmin/$cmax/0.005 -Z > $f.cpt   

 # Create the basemap    
 wtbmap=$(( $wtimap + 6 ))   
 htbmap=$(( $htimap + 5 ))   
 psbasemap -JX$wtbmap/$htbmap -R0/$wtbmap/0/$htbmap -B0 -K > $f.ps
}

create_contour() {
                           
 textPosx=`echo $xminBse | awk '{print $1 + 1.2}'`   
 textPosy=`echo $zmaxBse | awk '{print $1 - 1.2}'`   
 txt="$textPosx $textPosy 12 0.0 0 BL $fullname"   
 echo $txt | pstext -JX$wtbmap/$htbmap -R$xminBse/$xmaxBse/$zminBse/$zmaxBse -Wwhite -O -K >> $f.ps   
 # Display the image    
 grdimage $f.grd -JX$wtimap/$htimap -R$xmin/$xmax/$zmin/$zmax -C$f.cpt  -B$ax:"$xDesc":/$az:"$yDesc"::."$title":WSne -X2.5 -Y2 -O -K >> $f.ps   

 # Can use units on the contours if needed   
 units="Mm/min"   
 units=""   

 # Annotate contour lines every ${labeldistx} cm   
 contLabelDist=`echo $wtimap | awk '{print $1/2}'`   
 contLabelDist="d${contLabelDist}c"   

 # Include contour lines with annotations   
 grdcontour $f.grd -C$ctc -JX -A$cta+v+u$units -G$contLabelDist -B -R -O -K >> $f.ps  

}


Last edited by kristinu; 09-11-2012 at 04:46 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variables and functions

I have a script that ultimately will FTP data to certain directories based on a character in the filename. I am creating a function within my script to handle the FTP call. Are the variables that are setup in the original script accessible to the function? If not, is there a way to allow them to... (4 Replies)
Discussion started by: dfb500
4 Replies

2. Shell Programming and Scripting

awk - arithemetic functions with external variables

I'm trying to get awk to do arithmetic functions with external variables and I'm getting an error that I cannot figure out how to fix. Insight would be appreciated money=$1 rate1=$(awk -F"\t " '/'$converting'/{print $3}' convert.table) rate2=$(awk -F"\t"... (2 Replies)
Discussion started by: DKNUCKLES
2 Replies

3. Programming

Trouble with Date Variables and Functions in PL/SQL

Hi, In the course of my script i have to compare SYSDATE with the 15th of the current month: if it is greater than i should set a variable date to 15th of the next month if less than i should set it to the 15th of the current month. In other words the question is how to set a date variable... (2 Replies)
Discussion started by: fmina
2 Replies

4. Shell Programming and Scripting

[bash] reassigning referenced variables in functions

Hello all, Problem. ---------- I'm trying to reassign a referenced variable passed to a 'local' variable in a function but the local variable refuses to be assigned the content of the referenced variable. Any ideas would be appreciated. Objective. ----------- Eliminate all $VAR... (1 Reply)
Discussion started by: ASGR
1 Replies

5. Shell Programming and Scripting

Mathematical functions in bash shell

Hi, How can i do the mathematical calculations in bash shell? Are the mathematical functions available in bash shell? Ex: pow ceil floor sqrt (5 Replies)
Discussion started by: cola
5 Replies

6. Shell Programming and Scripting

bash functions arguments

This script is called fuu; #!/bin/bash speak() { case $1 in 1)echo one ;; 2)echo two ;; 3)echo three ;; esac } speak exit 0 when i run fuu 2 i expect "two" like... (2 Replies)
Discussion started by: Tártaro
2 Replies

7. Shell Programming and Scripting

variables and functions

can somebody telll me what my values are not being displayed in the function func1() {oracle@im4s012nz1_DUMMY}$ cat x1.ksh #!/bin/ksh getpwd() ( set -x . /home/oracle/dba/bin/CyberArk/CyberArk_GetPass.ksh ORA_USER=$DB_UID ORA_PWD=$DB_PWD echo "Here I am 1... (6 Replies)
Discussion started by: BeefStu
6 Replies

8. Shell Programming and Scripting

Calling Bash Functions in the BG

I'm trying to call some functions in the background so that I can multitask in this script. Not working so hot. The functions I call don't ever seem to get called. I'm doing it the exact same way in another script and it's working like a champ so I'm very confused. Here's a pretty simple repro: ... (7 Replies)
Discussion started by: stonkers
7 Replies

9. Shell Programming and Scripting

ksh While Loop - passing variables to functions

I'm reading a text file using a while loop but when I call a function from within this loop it exits that same iteration … even though there are many more lines in the file to be read. I thought it was something to do with the IFS setting but it appears that a function call (when run... (3 Replies)
Discussion started by: user052009
3 Replies

10. Shell Programming and Scripting

Bash functions sequence ?

OK, I know function has to be defined first - in sequence - before it can be used. So the script has to be build "bottoms -up style, if you pardon my expression. I am running into a problem reusing function and breaking the sequence. It would be nice to be able to see the function... (10 Replies)
Discussion started by: annacreek
10 Replies
COLORGCCRC(5)							File Formats Manual						     COLORGCCRC(5)

NAME
colorgccrc - configuration file for colorgcc DESCRIPTION
A colorgccrc configuration file is used to configure the highlighting of the compiler output from colorgcc. SYNTAX
Each line consists of a keyword designating a configuration variable. The keyword is followed by `:' and then one or several values (depending on the keyword). Lines beginning with a hash mark `#' are comments. CONFIGURATION VARIABLES
g++ | gcc | c++ | cc | g77 | gcj | gnat | gpc Specifies the paths to the compilers. Takes one value; a path to the compiler. nocolor Specifies what terminal types colorization should be disabled on. Takes one or several values, separated by whitespace. srcColor Specifies the highlighting attributes source-code should be given. Takes one or several color attributes. See the section COLOR ATTRIBUTES for more information. introColor Specifies the highlighting attributes for normal compiler output. Takes one or several color attributes. See the section COLOR ATTRIBUTES for more information. warningFileNameColor | errorFileNameColor Specifies the highlighting attributes for the filename in a warning or an error, respectively. Takes one or several color attributes. See the section COLOR ATTRIBUTES for more information. warningNumberColor | errorNumberColor Specifies the highlighting attributes for the line-number in a warning or an error, respectively. Takes one or several color attributes. See the section COLOR ATTRIBUTES for more information. warningMessageColor | errorMessageColor Specifies the highlighting attributes for the message-text in a warning or an error, respectively. Takes one or several color attributes. See the section COLOR ATTRIBUTES for more information. COLOR ATTRIBUTES
The following attributes are valid for highlighting. clear, reset bold, underline, underscore, blink, reverse, concealed black, red, green, yellow, blue, magenta, cyan, white on_black, on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white SEE ALSO
gcc(1), colorgcc(1) HISTORY
Jan 15 2003: Initial version of this manual-page. REPORTING BUGS
Report bugs to <jmoyers@geeks.com> AUTHORS
Jamie Moyers <jmoyers@geeks.com> is the author of colorgcc. This manual page was written by Joe Wreschnig <piman@sacredchao.net>, and modified by David Weinehall <tao@debian.org>, for the Debian GNU/Linux system (but may be used by others). COPYRIGHT
Copyright (C) 2003 Jamie Moyers This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. Jan 15, 2003 COLORGCCRC(5)
All times are GMT -4. The time now is 07:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy