General :: Assign A Variable To The Output Value Of A Program?

Feb 6, 2011

so i wrote myself a very simple hellworld program in c++

...the usual stuff
int main()
{

[code]...

View 3 Replies


ADVERTISEMENT

General :: Assign Local Variable Values To Global Variable?

Feb 17, 2011

how to assign a local variable value to a global variable....

View 2 Replies View Related

Programming :: Search Within A Variable And Assign The Results To A New Variable?

Apr 25, 2011

how 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?

View 5 Replies View Related

Programming :: Assign Value Of C Variable To Shell Variable?

Apr 28, 2010

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 Related

General :: Assign An "here Documents" Section To A Variable In Bash?

Mar 11, 2011

Is 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>

View 4 Replies View Related

Red Hat / Fedora :: Assign A Variable To A Command?

Sep 10, 2010

I 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 Related

General :: Sed: Assigning Its Output To A Variable?

Feb 3, 2011

Kernel 2.6.21.5, GNU/Linux (Slackware 12.0).In this script,

Code:
semoi@darkstar:~$ cat rename4.sh
#!/bin/bash
INPUT="k3b_audio_0_04"

[code]...

View 3 Replies View Related

General :: Any Way To Store Output Of Command Into Variable?

Mar 3, 2010

I tried using the tail command in my shell script and storing that value in a variable a but an error keeps coming. Is there any other way to store the output of a command into a variable. Cannot Read text from text file and store it in a variable using shell script. The thing is I need a number from the file new.txt and use that number in my script

#!/bin/bash
a = `tail -1 new.txt|head -n 1`
echo $a

View 2 Replies View Related

General :: Need To Store Output Of Bitset() In A Variable / Possible In C++?

Mar 5, 2010

I need to store the output of bitset() in a variable ... is it possible in c++?

View 1 Replies View Related

General :: Can't Save Grep Output Into Variable / Solution For This?

Feb 3, 2010

I would like to grep two numbers out of a text file, and divide them.

Here is the script code...

It feels like grep saves a new line too? or what is happening? i simply can't divide them, as it handles the variables as they are empty (and prints the two numbers although they were not printed

View 6 Replies View Related

General :: Does The Output Of The Previous Command Get Stored In Any Variable

Mar 26, 2011

For example, when using bash you can use

Code:

to execute the previous command or

Code:

!<number> to execute the Nth command(use history to see the list). Or you can use

Code:

cd !-2:1

to cd into the value in the first field that was executed 2 commands ago Anyhow, say I run a command and the output is a path. Any way to cd and then some variable where OUTPUT of the previous command was stored? A variable that always stores the OUTPUT of the last command.

View 8 Replies View Related

General :: Storing A Variable In A Shell Script After Awk Output?

Feb 8, 2010

On command line I have no problem storing a variable e.g

Code:

:~/bin$ process=`ps -ef | awk ' $8 == "idesk" { print $2 }'`
:~/bin$ echo $process
26736
:~/bin$

When I try to incorporate this into a shell script I get a blank.

Code:

:~/bin$ cat process_idesk
#!/bin/bash
process=`ps -ef | awk ' $8 == "idesk" { print $2 }'`

[code]....

The process_idesk script has been chmoded to be executable by the user. I'm sure there must be a silly omission on my behalf.

View 3 Replies View Related

Debian Programming :: Assign Variable In Bash When Stdout Is Updated

Jan 17, 2014

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.

View 7 Replies View Related

Programming :: Bash Scripting...read A Value From A File Then Assign To Variable?

Feb 27, 2011

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 Related

Programming :: Bash Script: Assign Command Ouput To A Variable Without Executing It?

Feb 12, 2011

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]...

View 1 Replies View Related

General :: Count The Number Of Lines Inside A File And Put The Output Into A Variable?

Feb 1, 2011

i need to count the number of files and put the output into a variable. i used wc -l filename but i couldnt find an option to put the output to variable. example if the number o line is 5, i need the output of echo $x is 5.

View 3 Replies View Related

General :: Create A Single Line Of Output From Multiple Variable Lines Of Input

Feb 3, 2010

I need to create a single line of output from multiple and variable lines of input in a Linux bash shell script.

My input file looks like this:

Where there may be any number of umsecondaryphonenumber lines; if there is not a umsecondaryphonenumber line for a telephonenumber, I don't want to write any output.

So, the output file should look like:

The script I have so far is:

My question is - how do print each of the elements of an array in one record - i.e. what do I put in place of howdoiprintarray?

View 2 Replies View Related

Ubuntu :: Possible To 'assign' Program To Core?

Jul 26, 2010

Obviously I don't know that much about CPU architecture. I have a fancy new quad core CPU in the machine I just built. Now, given the current state of technology, two or many times three of those cores are pretty much sitting idle.My question is: Is there any way to utilize those extra cores with programs not optimized to take advantage of them? If I have some CPU intensive application, is there any way to tell it to utilize a core that's idling instead of the first core that's probably already got a bunch of processes running on it?

View 7 Replies View Related

General :: Unexpected Output From Program?

Sep 8, 2010

while doing socket/network programming, i am getting SSH-2.0-openssh4.7 error, instead of showing day time of server.general description i have Linux Box, with the help of putty i am connecting from windows system to Linux box,no problem in loging,after typing program, i am running the program with gcc. when typing ./a.out, it is showing SSH-2.0-openssh4.7, actually it should display daytime from linux box in both tcp and udp.

View 1 Replies View Related

General :: Program To Visualize Anything That Goes Through My Audio-output?

Jun 1, 2011

I'm looking for a program that will visualize anything that goes through my audio-output (in this case it's Spotify) and display it on the screen. Does this exist?

I'm running Ubuntu.

View 1 Replies View Related

General :: Assigning "find" Operation Output To A Variable?

Jan 7, 2011

I am assigning "find" operation output to a variable. I also need to have error info / stderr if nothing is found in the same variable itself.

e.g.

a=`find . -name "hello.txt" -type f`

I do not want any temp files to be in between infact, redirection.

View 5 Replies View Related

General :: Executing PHP File And Read Output To Program

Jun 29, 2011

I'm using Ubuntu and I'm programing with eclipse CDT. My goal is to execute a php file and read the output to my c++ program. To do so I thought I should use fork(), dup2() and execl. When in shell, the call "php myscript.php" worked just fine, but when in c++ I tried:
execl("usr/bin/php", "php", "home/geiger/workspace/SemiServer/server_content/myscript.php", NULL);
And it didn't work (the process wasn't terminated and I got no output). I tried different version of this call, like losing the "php" string and/or drop "home/geiger" from the path string, to no better result.

View 1 Replies View Related

General :: Redirection - Redirect The Output Of A Program To The Diff Command?

Jan 13, 2011

I have a program that writes to stdout. Is there a way that I can redirect the output to the linux diff command or do I have to write the output to a file and then compare that. For example I have a bunch of test input files for a program and the corresponding expected output in another set of files. And I'd like to do something like ./program < t1.input | diff t1.expected.

View 3 Replies View Related

Programming :: Piping Cat Output To Variable?

Jan 10, 2010

New to ubuntu and shell scripting in general... currently I stored some data into a text file. Right now, I would like to output the data from the text file and store it into a variable. Here's what I have so far:

READ_FILE=$(cat $FILE_NAME)

This definitely works and READ_FILE has the necessary data. However, this command will trigger an output to std output and I will see data on the screen, which is not what I want. I tried:

cat $FILE_NAME | $READ_FILE

and various other variants of this. It does not output to std output but neither does anything gets stored into $READ_FILE. I tried:

cat $FILE_NAME >> $READ_FILE

and it arrived at an error of "ambiguous redirect".

View 12 Replies View Related

Ubuntu :: C++ - Can't Pass System Output To Variable ?

Sep 8, 2010

I have a line that looks something like this:

Code:

How do i put its output in a variable?

View 9 Replies View Related

Programming :: Retain The Eol In Bash Variable Or Ssh Output?

Jan 17, 2011

I have to save the result of ssh/grep into a file to keep the eol ("/n"):

ssh $SSH_OPTIONS $USER@$NODE "cd $LOG_DIR; grep -h '$pattern' log.*" > $file

So that when I grep on the local file again later, it can be printed out with original log lines. Otherwise, the log lines will be dropped and lines becomes concatenated into a single line, e.g., if I rewrite the script in this way, echoing the $result is not a good idea..

result=`ssh $SSH_OPTIONS $USER@$NODES "cd $LOG_DIR; grep -h '$pattern' log.*"`

is there some workaround that I can save it to a variable rather than file but still keep the eol? That will simplify my script and don't need to do all those I/Os!

View 3 Replies View Related

Programming :: Java Output Into Bash Variable?

Feb 20, 2011

I have a bash script that calls a java class method. The method returns a string to the linux console when run independently. how can I assign the value from the java method to a variable in a bash script?running the script: java -cp /opt/my_dir/class.method [parameter]

output: my_string if added in a bash script:

read parameter
java -cp /opt/my_dir/class.method [parameter] | read the_output
echo $the_output

the above doesnt work, I also tried unsuccessfully:

the_output=java -cp /opt/my_dir/class.method [parameter]
the_output=`java -cp /opt/my_dir/class.method [parameter]`
java -cp /opt/my_dir/class.method [parameter] 2>&1

How can i get the output stored into the_output variable?

View 6 Replies View Related

General :: Program That Reads Multiple Pipes / File Descriptors And Writes To Standard Output

Feb 23, 2011

Is there already a program that reads multiple pipes or file descriptors and writes to the standard output (not splitting lines).Like cat, but reading all files simultaneously and preserving lines.It is needed to avoid coding of select/epoll loops or using multithreading in simple programs. Like "select loop for bash".

View 1 Replies View Related

Ubuntu :: Cannot Pipe Gdialog Output To Variable / Sort It?

Mar 20, 2010

I'm trying to use the output from gdialog's input box in another command with no success. code...

View 3 Replies View Related

Programming :: Receive Command Output And Store It To A Variable?

Apr 3, 2010

Suppose I want to account number of files beginning with abc , I can use "ls 'abc* | grep abc | wc -l", this will return me a number.
I want to store this number in a variable, say var1, so I tried
1. "ls 'abc* | grep abc | wc -l |read var1", but this didn't work as var1 has no value somehow.
2. var1='ls 'abc* | grep abc | wc -l', this just assign the entire string "ls 'abc* | grep abc | wc -l" to var1, which is not I wanted.

I don't want to store the value to a temporary file and then read the value from that file. I think there should be a direct way to get the value, but don't know how. I know in tcsh, one can just use set var1='ls 'abc* | grep abc | wc -l', but it also doesn't work in bash. Can anyone give any clue about this?

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved