General :: Assign Local Variable Values To Global Variable?
Feb 17, 2011how to assign a local variable value to a global variable....
View 2 Replieshow to assign a local variable value to a global variable....
View 2 RepliesIs it possible to create a global struct variable with predefined member values?Only one instance of that struct is ever needed.
View 1 Replies View Relatedhow I can search within a variable and assign the results to a new variable. I'll use the following as an example -
cars="Audi BMW Cadillac Chevy Dodge Ferrari Ford Mercedes"
list=`echo ${cars} | egrep -o '<A?+|<C+'`
with the echo command I get the following output assigned to list -
A
C
C
What I'd like to get for output is -
Audi
Cadillac
Chevy
how I could do this regardless of upper/lower case letters?
included shell script inside c program, and i wanted to assign the value of c variable to shell variable..Can any one please suggest me how to do it?
View 8 Replies View RelatedI have a hard time with my bash script.
It forget global variable's value.
First look at my script.
Code:
Echo "PKGS is [$PKGS] in after loop"
And data file for it is below. Let's name as list.txt
Code:
As you see, PKGS variable in loop has correct value.
However, after loop I can not get proper value for it.
I'm trying to use a global variable to apply a condition within a script.
The idea is to use this variable set to e.g. 1 or 2 to run a different part of the script accordingly. I can set the global variable with e.g.
Code:
export WL0=1
run my part of script, increment it by 1 with e.g.
Code:
WL0=$((WL0+1))
but if I re-run the script my WL0 is still set to 1!
I've also tried to add an
export $WL0 at the very end of my script (after the math) but this doesn't change the global variable apparently.
so i wrote myself a very simple hellworld program in c++
...the usual stuff
int main()
{
[code]...
I have been reading the Wikibook on C Programming for quite some time and am up to the variable part. I did learn several new things, like that too many variables hog memory.
What I want to know is how to assign a variable to the keyboard (in the C/C++ family) as such that the user has to type it in.
I am supposed to create an environment variable with the PRINTER variable, which should resolve to the word sales. Would the command be like this?: env PRINTER - NAME=SALES (is this the command to create that variable with resolving the word sales to it?)
View 3 Replies View RelatedI can print a specific line of a file with:$ sed -n '20p' myFileHow can I store it in a variable (in a shell script)?(I wasn't successful with "myVar=sed -n '20p' myFile" for example)
View 2 Replies View RelatedI am trying to import variable values from a profile file to a perl program.
I am using the below command for doing it.
Quote:
system (". /opt/bbfb/bin/setbbfbenv $codeset");
the above command does make variable values available to the running perl program..
Can some one help me on this front..
Code:
int main()
{
int pi;
int i=10;
pid=fork();
[code]....
Q 1. The value of the variable pid returned by the fork() function will be greater than 0 in the parent process and equal to zero in the child process? but during forking, there values are exactly copied so what's went wrong here?
Q 2. "changes to the variable in one process is not reflected in the other process" why it is so? >> Even if we have variable i declared as a pointer or a global it wont make a difference.
Code:
int main()
{
int i, pid;
i=10;
printf("before fork i is %d
[code]....
Q. Through this program it is clear that both process is using the data from the same location, so where's the original value is residing when the child process is in execution.?
I am writing a script that calls a program which writes a lot of lines to stdout continuosly. If the last line in stdout has some regex, THEN, certain variables are updated. My problem is that I don't know how to do that.
A simplified example would be (it's not my exact case, but it I write it here to clarify): suppose I issue a ping command (which writes output to stdout continuously). Every time that the response time is t=0.025 ms, THEN, VARIABLE1=(column1 of that line) and VARIABLE2=(column2 of that line).
I think the following code would work in awk (however, I want the variables in bash and I don't know how to export them)
Code: Select allping localhost |awk '{ if ( $8 == "time=0.025" ) var1=$1 var2=$2}'
In the previous code, awk analyzes each line of the output of the ping command as soon as it is created, so the variables $var1, $var2, ... are updated at the appropriate time. But I need the "real-time" updated values of $var1, $var2 in bash, for later use in the script.
At my wit's end I can't find anything that I understand well enough to use. This is for a Unix class, we are working with shell scripting. File1 has 5 in it and File2 has 100 in it.The teacher wants us to read the values then do the math. This is what I have so far:#!/bin/bashvar1='cat File1'var2='cat File2'var3=`echo "scale=4; $var1 / $var2" | bc`echo The final result is: $var3
View 9 Replies View RelatedIs it possible to assign an "here documents" section to a variable in bash?I would like to assign the following to a variable:
Code:
<html>
<body>
<p>THis is a test</p>
</body>
</html>
I'm trying to execute the following command within a bash script:
Code:
tac /var/log/system.log | head -1
The script I wrote is:
[code]...
can i use the value of one variable to generate a name for another variable? for example i want to use the counter from a "do while" loop to name and define a variable each time the loop executes. for example
objectnames1=`ls -a`
objectnames2=`ls -a`
etc.
i don't have a script yet but each time through the loop i intend to cd to a particular directory and then define a variable containing a list of each object in that directory as values. for the rest of the script to work, each variable generated has to be unique, and i can't think of a good way to accomplish this.
if using a value from one variable to name another isn't possible, can anyone think of a more elegant solution? i know limited syntax but i'm willing to read up...
I am trying to alter the character position of residue numbers above 999 in a pdb file.The following script is an attempt to:1) Get all unique pdb residue numbers (in column 5) using awk and assign it to a variable i.2) Loop through all the values in $i and if it is greater than 999, shift that number one character to the right using sed.However, the script only manages to alter the final residue numberCould anyone please advise how I can loop through all values in $i and shift it one character to the right?
#!/bin/bash
# Script to alter position of residue number in pdb file for resid above 999
i=$(awk '{print $5}' wt-test.pdb | uniq)
[code]...
I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.
For example:
Code:
Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).
my script has a variable which comes in the form +00.00 +0.00 -00.00 or -0.00 (the numbers can be any in that form) for any that have a + symbol I need to remove the +, but if it has a - symbol it needs to stay.
i need to make a new variable with the string from the old variable btut without any plus sign. I have tried a lot of different ways with no success, each thing I tried either left the + or removed the entire string. I think this should work but doesn't
foo=+12.40
bar=${foo#+}
I have a text file i that has a mailTo: NAME in it. In a bash script i need to extract NAME and put it in a $variable to use. How do i do this?
View 2 Replies View RelatedI want to know is there some more efficient way of passing a pointer to a local variable as a parameter to a function in x86 asm? Right now I have to move the base pointer to a temp register, subtract from the register and pass that, like this (assuming a local var at esp-4):
Code:
mov eax, ebp
sub eax, 4
push eax
Is there a better way?
My script.
This is may script:
Code:
Problem: Output file doest not exclude the values in grep -av
I am new to using 'pragma pack' and here is what I am running into :
Process A:
a.h -> defines a struct XYZ as PACKED and is of size 44bytes
a.c -> includes a.h and is able to print the size as 44 bytes.
Process B
b.c -> includes a.h,
b.c -> gets a message from process A, with struct XYZ in the message as data.
b.c -> After getting message, it is unable to print the elements of struct correctly. This is because the sizof (XYZ) in b.c is seen as 48 bytes.
I suspect, in b.c, the local variable of struct XYZ is being padded and not PACKED.
It's good that GCC support intel inline disassembly syntax, but it cannot even simply address local variables/parameters properly, making itself stupid and essentially useless, look at the following:
int myfunc(float f){
int x;
float fa[8];
asm(".intel_syntax noprefix
"
"mov eax, [x]
[Code]...
This loop is part of a bash script which takes multiple arguments.
Code:
for ((i=1;i<=$number;++i)) ; do
offset=$(($i+5))
[code]...
On one of my servers I see this when I log in. What does this mean and how can I get it to go away? Everything seems to work fine, but none of my other machines give this error.
View 5 Replies View RelatedI want to use a combination that avoids alphabetic/punctuation characters because that way I have a consistent physical position on different layouts. Control_R+Menu fits that requirement and is also located at a very convenient position.This combination used to work in KDE 3.5 for the global kxkb switch action, or any keyboard action for that matter. In KDE 4, trying to assign Menu by pressing the Menu key always activates the keyboard trap widget's context menu, in this case giving me the What's this?How do I work around that problem? Alternatively, do you have a snippet that I can paste into $HOME/.kde/share/config/kglobalshortcutsrc and which works?
View 1 Replies View RelatedI was working my way through the steps for downloading and installing the kernel source I have done this on ever Fedora release, so this is a new error for me. The error was from yum-builddep. Here is the command and error output:
[Code]
While the symptom is a script error, I am not sure what is causing the problem.
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...