Sponsored Content
Top Forums Shell Programming and Scripting How to put output of one command into a variable Post 302409008 by joker_789us on Wednesday 31st of March 2010 03:28:16 AM
Old 03-31-2010
How to put output of one command into a variable

Hi,
Let say I have these 3 files (state, list and myscript). I want to be able get the sample output like below when I run myscript. Any one know how to fix the code? TIA.


~~~~~~~~~~~~~~~

Code:
> cat /home/state
CA
 
> cat /home/list
CA 100 50 20
AUS 120 61 10
 
> cat myscript
#!/bin/sh
st='cat /home/state'
grep $st /home/list
 
> ./myscript    # this is the output I want.
CA 100 50 20


Last edited by Franklin52; 03-31-2010 at 04:32 AM.. Reason: Please use code tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command output to a variable.

With cut -c 8-13 myfile, I am getting some numeric value. In my shell script I am trying to assign something like this, var=cut -c 8-13 myfile But at the time of execution I am getting -c is not found. If I dont assign, then script executes well. Can we not simply use the value from one... (8 Replies)
Discussion started by: videsh77
8 Replies

2. UNIX for Dummies Questions & Answers

How to store output in variable when put in background

Hi, How do I store following command output: export RESULT=`date` & It works when I do : export RESULT=`date` But what I need is when command put it background, I also need that output going to RESULT variable. Is there any way ? Thanks Sanjay (1 Reply)
Discussion started by: sanjay92
1 Replies

3. Shell Programming and Scripting

Put the output of grep in a variable

Hi, in a shell script how can I put the result of a grep command in a variable : myvariable=grep mystring myfilename Thank you. (3 Replies)
Discussion started by: big123456
3 Replies

4. Shell Programming and Scripting

get characters from output of a command in a variable

Hi, i have two questions, I am new to programming 1. I have an output of a command and i want to get some specific part of it in a variable. i am trying sr=`some comand xyz| grep 'Last Changed Rev:' | cut -c19-` now variable sr gets a end of line character at end. output of the command... (3 Replies)
Discussion started by: muaz
3 Replies

5. Programming

Command output into a variable

Hi, with this command: cu -l /dev/ttyACM0 -s 9600 > name.txt I put the output of the port in a txt Is posible to do the same (or similar) in a var directly, inside a C program? cu -l /dev/ttyACM0 -s 9600 > variable ? I have trying this withs pipes, but i dont know how to... (6 Replies)
Discussion started by: daaran
6 Replies

6. Shell Programming and Scripting

set variable to command output

I'm hoping you guys can help me out here. I've been trying different methods to try and get what IW as hoping would be a fairly simple script but has turned into a pain. Bit of background - I am writing a script to check values in certain failes to ensure they are corerct. I'm runnign this on... (2 Replies)
Discussion started by: stuc
2 Replies

7. Shell Programming and Scripting

how to save an output of a command in a variable

Hi, in shell script, i have the command swstart -p which returns an output. i want to store the output of this command into a variable. how i can do that excerpt from the script #!/usr/bin/ksh # # # # Program: swstart -p # # Description: Starts the sentinels on Slave server ... (4 Replies)
Discussion started by: lookinginfo
4 Replies

8. UNIX for Advanced & Expert Users

ls output into a read command as a variable

I'm working on a short BASH script on my Ubuntu box that will run powerpoint scripts with MS Powerpoint Viewer 2007 via WINE. I can run the presentation when I run it manually but what i'd like to do is have the script look for the newest file then run it. #! /bin/sh # Start the newest... (2 Replies)
Discussion started by: binary-ninja
2 Replies

9. Shell Programming and Scripting

How i can put the result of a command inside a bash variable?

#!/bin/bash #... for i in `ls -c1 /usr/share/applications` do name="cat $i | grep ^Name= | cut -d = -f2" echo $name #... done Now inside name as output is present: while i want only the result of the command. Ideally i would like obtain that information using only bash ... or... (8 Replies)
Discussion started by: alexscript
8 Replies

10. Shell Programming and Scripting

Shell script variable $1 used with put command

I have the following script used, i am new to shell scripting. tryign to understand. in the put $BASE_FOLDER/$base_name holds which path. What does it mean by $1 second path in put command is it constructing this path: /user/hive/warehouse/stage.db/$1 what is $1 holding in above path. ... (2 Replies)
Discussion started by: cplusplus1
2 Replies
AMQP-CONSUME(1) 						 RabbitMQ C Client						   AMQP-CONSUME(1)

NAME
amqp-consume - Consume messages from a queue on an AMQP server SYNOPSIS
amqp-consume [OPTION...] {command} [args...] DESCRIPTION
amqp-consume consumes messages from a queue on an AMQP server. For each message that arrives, a receiving command is run, with the message body supplied to it on standard input. amqp-consume can consume from an existing queue, or it can create a new queue. It can optionally bind the queue to an existing exchange. By default, messages will be consumed with explicit acknowledgements. A message will only be acknowledged if the receiving command exits successfully (i.e. with an exit code of zero). The AMQP "no ack" mode (a.k.a. auto-ack mode) can be enable with the -A option. OPTIONS
-q, --queue=queue name The name of the queue to consume messages from. If the --queue option is omitted, the AMQP server will assign a unique name to the queue, and that server-assigned name will be dixsplayed on stderr; this case implies that an exclusive queue should be declared. -e, --exchange=exchange name Specifies that an exclusive queue should be declared, and bound to the given exchange. The specified exchange should already exist unless the --exchange-type option is used to request the creation of an exchange. -r, --routing-key=routing key The routing key for binding. If omitted, an empty routing key is assumed. -d, --declare Forces an exclusive queue to be declared, even when it otherwise would not be. That is, when a queue name is specified with the --queue option, but no binding to an exchange is requested with the --exchange option. -A, --no-ack=routing key Enable "no ack" mode: The AMQP server will unconditionally acknowledge each message that is delivered, regardless of whether the target command exits successfully or not. EXAMPLES
Consume messages from an existing queue "myqueue", and output the message bodies on standard output via cat: $ amqp-publish -q myqueue cat Bind a new exclusive queue to an exchange "myexch", and send each message body to the script myscript, automatically acknowledging them on the server: $ amqp-consume -A -e myexch ./myscript SEE ALSO
librabbitmq-tools(7) describes connection-related options common to all the RabbitMQ C Client tools. AUTHOR
The RabbitMQ Team <info@rabbitmq.com> RabbitMQ C Client 2011-01-01 AMQP-CONSUME(1)
All times are GMT -4. The time now is 04:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy