Sponsored Content
Top Forums Shell Programming and Scripting functions and variables in bash Post 302699449 by kristinu on Tuesday 11th of September 2012 05:31:00 PM
Old 09-11-2012
That's good. So now I consider the following toy problem. I have two bash scripts as follows

Code:
cat colors.bash

#!/bin/bash  

colors() {   
  red="red"  
  blue="blue"   
  green="green" 
} 

car() {
  color_car="$red"
} 

pen() {
  pen_color="$blue"
}

Code:
cat property.bash  

source colors.bash  
my_property() {
  echo "$color_car"
}

I want to have the function my_property returning red. My problem is that I do not want to call the function colors inside car before setting
Code:
color_car="$red"


Last edited by kristinu; 09-11-2012 at 06:45 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
RBASH(1)						      General Commands Manual							  RBASH(1)

NAME
rbash - restricted bash, see bash(1) RESTRICTED SHELL
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to bash with the exception that the follow- ing are disallowed or not performed: o changing directories with cd o setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV o specifying command names containing / o specifying a filename containing a / as an argument to the . builtin command o specifying a filename containing a slash as an argument to the -p option to the hash builtin command o importing function definitions from the shell environment at startup o parsing the value of SHELLOPTS from the shell environment at startup o redirecting output using the >, >|, <>, >&, &>, and >> redirection operators o using the exec builtin command to replace the shell with another command o adding or deleting builtin commands with the -f and -d options to the enable builtin command o using the enable builtin command to enable disabled shell builtins o specifying the -p option to the command builtin command o turning off restricted mode with set +r or set +o restricted. These restrictions are enforced after any startup files are read. When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script. SEE ALSO
bash(1) GNU Bash-4.0 2004 Apr 20 RBASH(1)
All times are GMT -4. The time now is 10:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy