General :: Declare Global Variables In Bash?

Jan 23, 2010

I have a problem with a very big script I wrote in bash, and now I need to modulirize it in at least four smaller scripts. The problem is, that most of the variables I have will need to be shared by all scripts.

My question is: is there a way to declare global variables in bash? So that I can use and change them in any of the scripts and every change in the variable can be "seen" by the other scripts later.

View 4 Replies


Ubuntu :: Bash Script With Variables And Editing Variables

Apr 6, 2011

mkvmerge -o <filename without extension>_TV.mkv -S <filename> && mkvextract tracks <filename> 3:<filename without extension>.*** && perl /home/brian/Desktop/ <filename without extension>.*** && rm <filename without extension>.***

Doing these commands for multiple command line file inputs is the goal. So I can just type ./ *.mkv in my terminal.This is what I have so far, but it doesn't work whatsoever.

View 2 Replies View Related

Programming :: Accessing Global Variables In Script?

Apr 10, 2011

I have a script that goes like this

step 1 - install sdk

step 2 - update ~/.bashrc export some new variables

step 3 - check said variables, if they return a value then we know a reboot has taken place and we can continue to step 4. otherwise halt and isssue a warning that a reboot is needed.

Ok, so this works if I just execute the script when I am logged on as root, and after a reboot & rerun of the script I can check the variables exist and the program will continue as expected. only when I am logged on as root will the variables I exported in bashrc return a value. If I run the script as sudo root the values are blank.

View 2 Replies View Related

Programming :: Avoiding Global Variables In Kernel Modules?

Jun 27, 2010

I have two modules A and B in the kernel which i am trying to hack by introducing a variable in A which is of type 'extern' (and using EXPORT_SYMBOL) and then calling it in B. Now the problem is how to introduce that variable in module A. Currently i have made a global variable and it works fine but global variable in kernel is a bad bad thing.

I tried having an 'extern' function in A which have that variable and calling that function in module B, but then again how would module A use my variable unless the variable is available outside the scope of that function and that again means a global variable.

View 3 Replies View Related

Red Hat :: Global Variables Not Taking Effect When Set Via Called Script

Aug 3, 2010

I have a script which lists all the SID listed in /etc/oratab and then after the user select which SID to set, it calls another script to set the SID and other environment variables.

The script runs just fine and does all that is expected, but the variables are not set permanently, can't figure out why. Everything works fine when I run the out of this script.

Here is the script:

View 9 Replies View Related

Programming :: Global Or Server Variables - Array Connection Oriented

May 20, 2011

I have a general question regarding php. Suppose that I want to have an array that stores connection-specific data, that can be anything IP address or something similar. However, whenever I use global or server variables (i.e. GLOBALS or _SERVER) the array created in this way is kind of connection-oriented, so that for each connection there is a separate instance of this array. Maybe it has something to do with the MPM of Apache, but I am not sure. Is it possible to implement an array that stores information about all connections that are at a system? In this way, each connection can chip in and upload it with data? Also, I would rather not use cookie's.

View 3 Replies View Related

General :: Bash Script - Forget Global Variable's Value?

Apr 9, 2011

I have a hard time with my bash script.

It forget global variable's value.

First look at my script.


Echo "PKGS is [$PKGS] in after loop"

And data file for it is below. Let's name as list.txt


As you see, PKGS variable in loop has correct value.

However, after loop I can not get proper value for it.

View 5 Replies View Related

General :: Referring To Variables In Bash?

Sep 13, 2010

Is there a difference when variables are referred to as $variableName and ${variableName} in bash?

View 1 Replies View Related

General :: Join 2 Variables In A Bash Script?

Aug 12, 2011

I have $db and $DATE set in my bash script, then I need to join them like this: mysqldump --user=usr --password=pss --databases $db | gzip > /backups/sqlNew/$db_$DATE.sql.gz;

Unfortunately, that doesn't work. How do I properly join those 2 variables into a filename?

View 1 Replies View Related

General :: Dynamic Variables And Heredocuments In Bash?

Apr 4, 2011

I've created a script that put in dynamic variables the value HELLO 1, HELLO 2 HELLO 5. And I put the values of this variables in the file text.txt. Here's the script:

for i in $(seq 1 5); do eval ${i}=$(cat << EOF "HELLO" $i EOF); done
cat > text.txt << EOF


View 1 Replies View Related

General :: Possible To Pass JavaScript Variables To Bash?

Apr 18, 2011

Can I pass javascript variables to bash script? If possible in bash script what code should I insert to receive javascript variables.

View 14 Replies View Related

General :: SQL Command Output To Bash Variables?

Aug 2, 2010

I would like to run a bunch of SQL commands from mysql client in bash. However, I would like to store the output in different variables. E.g.

var1=`mysql -u[user] -p[pass] -D[dbname] -e "Query1"`
var2=`mysql -u[user] -p[pass] -D[dbname] -e "Query2"`


View 5 Replies View Related

General :: Concatenate Two Environment Variables In Bash?

Nov 9, 2010

How do I concatenate two environment variables in bash?

View 3 Replies View Related

General :: Sourcing Variables From ~/.bash.rc And Keeping Them Across Logouts

Sep 7, 2011

I've been writing a bunch of bash scripts to make possible non-interactive, secure, cron-based SVN checkouts with CollabNet's SVN client and GNOME Keyring Daemon (aka GKD) and one of the scripts was designed to start GKD, harvest its output, essentially a couple of environment variables, and export those variables in shell of a user the script is run as. All upon user login by sourcing a bash script in ~/.bashrc.The problem is that those environment variables will not be exported, because the script is being run in a sub-shell that exits upon it completion and environment variables get unset for good.Well, the question is how can those variables be set permanently, meaning they're exported and kept untouched even across login-logout sessions?

View 1 Replies View Related

General :: Which Environment Variables Not Inherited By Bash Shells

Jan 2, 2011

I am using Linux some years, but since I built a LFS, I feel noobish again. Now with the help of BLFS I am setting up my environment and somewhere I incidentally read, that not every variable is inherited by a child Bash shell. As for the $PS1 and $PS2 variables I know, that they are not inherited by non-interactive Bash shells (and there is no reason why they should in my opinion). Well, as for my first thread I hope the title gives enough information on what I want to know. But anyways: Which environment variables are not inherited by Bash shells?

View 1 Replies View Related

General :: Bash Read All Environmental Variables Set By Other Shells?

Jul 23, 2010

For example, if I'm in csh, I can use `setenv VARNAME varVALUE` while I can use export in Bash. Given that the environmental variables are created, can BASH read env vars from csh and vice versa?

View 2 Replies View Related

General :: Changing Shell From C To Bash - Apps Or Variables?

Jun 21, 2010

I have a user that has been used for long time now that runs o C Shell... now there is a need to change it to Bash Shell? Can I cause a problem changing his shell from C to bash? I mean apps or variables?

View 2 Replies View Related

General :: Exit Bash Script - Add - Del - Edit User From Certain File Using Different CASE Variables

Mar 6, 2010

I have made a simple bash script through which i can add, del, edit user from certain file using different CASE variables. like
1. adduser
2. del user
3. edit user

Now i want to add a exit CASE like
1. adduser
2. del user
3. edit user
4. exit

Now i want to make a script such a way that, if user input is 4 then only script quit. I used with exit function also but it didn't work. if user press ENTER or other keys then also it quit the program.

View 6 Replies View Related

General :: Unable To Declare A Variable In Cygwin?

Jan 21, 2010

I recently installed Cygwin on my windows vista to practice on Linuxunix commands.I am unable to do a simple task of declaring variables on the command prompt I am trying:

$ vech=Bus
$ echo $vech
bash: vech : command not found

What am I missing? Do i need to add something to .bashrc? Also, I remember right click on the shell command gives the ability to copy or paste text from the shell. I am using Bash, how do I copy n paste text on shell window?

View 4 Replies View Related

Programming :: Global Bash Shell Functions - Line 2: Echotm: Command Not Found

Sep 13, 2010

I wonder if there is anyway to make a user-defined bash shell function global, meaning the function can be use in any bash shell scripts, interactively or not. This is what I attempted:


$ tail -n 3 /etc/bashrc
echotm () {
echo "[`date`] $@"


View 11 Replies View Related

Ubuntu :: BASH Script Not Recognizing Variables

Jul 25, 2011

I'm trying to write a bash script, and for some reason Bash doesn't seem to like any of my variables _except_ the one used in a loop.What's going on? The same problem with MYS occurs regardless of its name, whether it is declared or referenced before, after, or inside the loop, and whether it is a string, integer, or floating-point number. Also, as far as I can tell, everything related to Bash is up to date.

View 7 Replies View Related

Ubuntu :: Variables In Bash Alises Not Working With 11.04

Jul 26, 2011

I am trying to use the following bash alias:

I've been able to get this working under mac and solaris.

I've also tried not escaping the vars.

Anyone know if this is doable with ubuntu's bash shell? (or any meaningful workaround other than writing a script for this?)

View 2 Replies View Related

Programming :: Using Grep / Variables In Bash Script

May 10, 2010

I'm trying to write a bash script and I'm having trouble with it.I have a list of DNS entires from a file called zoneExport.txt.Than I want to parse a log file to see if that DNS entry has been queried for. So I'm running a grep command and trying to save it into a variable. What I'm looking for is a variable ($varGrepQ) that has the number of matches for the grep query. I will then run this through an if statement and do some things from there..

But my problem right now is with this grep query. It keeps outputting '0' even when I know there are records in that file and when I run the same query on the command line I get the actual count. My thought is that the $record variable is not passing right.

View 4 Replies View Related

Programming :: Counting Variables In Bash Script

Nov 13, 2010

If I read in variables entered by the user, how can I check to make sure the correct number of variables were entered? For example, after reading in a data file and making it into an array, I have:echo "To check the data, enter the first element number, last element number and step size as x y z:"read x y z.It then goes on to start a loop, but what I would like now (before the loop) is a check to see if three variables have been entered, before the rest of the script continues.

I've tried specifying the variables as $1, $2 and $3, but if I echo $#, the value comes out as zero, so it's obviously not working.

View 9 Replies View Related

Software :: Bash Scripting And Integer Variables?

Jun 6, 2010

Are there numerical variables (like type int in C) in the shell script language of bash? Say I want a counter to increment each time a loop is traversed.

View 1 Replies View Related

Programming :: Bash: Making A Variable Out Of Two Other Variables?

Mar 18, 2010

I need to find the value of:

My script asks for the name you want to look up and I want it to return the value of $Namenumber

I was thinking:

but this returns


but does not actually resolve what the variable $Namenumber is equal to.

View 4 Replies View Related

Debian :: BASH Scripting - How To Use Variables With Filename Spaces

Jun 25, 2015

I am trying to create scripts to move files over from one directory to an ftp server and there is this one file with spaces that bash is see each word as being a file, here is the variable i am trying to use:

Code: Select allLOCL = '/mnt/cifs/"File name with spaces"/'
cd  $LOCL
ls -l

View 3 Replies View Related

Ubuntu :: Python - Export Variables To Bash Commands?

Feb 19, 2010

I created variables in python and would like to be able to incorporate those into bash commands that will be mixed into the script. Example:

name=raw_input("Type your name and press ENTER: ")
import os
os.system( echo "name")

Of course this doesn't actually work, but i think you get an indication of what I am trying to do.

View 1 Replies View Related

Ubuntu :: Assign Values To Bash Variables From A File?

Jun 9, 2010

Is there an easy way to get a line from a text file into a variable in a bash script?

I have a file called outside_temp that has a single number, say, 63.2

I would like to make a variable in a BASH script have that value.

I know how to use the input redirection and reassignment of stdin using code...

View 1 Replies View Related

Ubuntu :: Bash ${variables} : Replace Last Instance Of Regexp?

Mar 10, 2011

I have something like...

# echo ${var/%e/E} doesn't do anything because i can only replace "r" or "er" this way


View 1 Replies View Related

Copyrights 2005-15, All rights reserved