Passing output to variable instead of file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing output to variable instead of file
# 1  
Old 05-27-2008
Passing output to variable instead of file

Hi,

In normal shell scripting, how do you pass the output of a command to a variable, instead of a file and be able to use it later?
The code is:

#!/bin/bash

who | cut -d" " -f1 > onlineusers

Instead of passing the output of the above command to the file called 'onlineusers' highlighted in red, how do you pass the output to a variable or to any other sort of container and could be made use of later?
# 2  
Old 05-27-2008
Like this:

Code:
variable=$(who | cut -d" " -f1)
variable=`who | cut -d" " -f1`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing output parameter(Oracle) to variable in ksh Script

Hello, I have researched and tried many way to pass OUT parameter to be stored in variable in KSH Script.Still not success, please help. Here is my Store Procedure. create procedure testout3(v_in varchar2,v_out OUT integer) as begin v_out := 1; end; Here is my testvout.ksh #!/bin/ksh... (1 Reply)
Discussion started by: palita2601
1 Replies

2. UNIX for Beginners Questions & Answers

Passing a file name to a variable

Below is the command mv AP_FLEXCUBE_INTERFACE10.txt FTPYMNTE_`date "+%Y%m%d%H%M%S" | tr '' ''`.TXT it is changing the file name to a different name according to time stamp dynamically. I want to capture that dynamic file name present in the directory to a variable . After that i want to... (6 Replies)
Discussion started by: sujit das
6 Replies

3. Shell Programming and Scripting

Passing sqlplus output to shell variable

Hi , I am using below code : for i in `ps -ef|grep pmon|awk {' print $8 '}|cut -f3 -d'_'|grep -v '^grep'` do ORACLE_SID=$i export ORACLE_SID; dest=`sqlplus "/ as sysdba" <<EOF set heading off feedback on verify off select DESTINATION from v\\$archive_dest where target in... (5 Replies)
Discussion started by: admin_db
5 Replies

4. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

5. Shell Programming and Scripting

Passing Shell variable from file to another command

Hi all, I have a file looks like AAAA 111 BBBB 222 CCCC 333 need to pass variable value like var1=AAAA and var2=111 to another command for three times with next values. stuck over here cat file | while read line do export var1=`awk '{print $1}'` echo $var1 export var2=`cat file... (3 Replies)
Discussion started by: rakeshtomar82
3 Replies

6. Shell Programming and Scripting

Passing variable from file to Oracle

cat a1 scott robert tom test script : #!/usr/bin/ksh for NAME in `cat a1` do VALUE=`sqlplus -silent "nobody/bobody01@testq" <<END set pagesize 0 feedback off verify off heading off echo off select username from dba_users where username=upper('$NAME'); END` if ; then echo... (3 Replies)
Discussion started by: jhonnyrip
3 Replies

7. Shell Programming and Scripting

Passing variable as a file-Scripting Help

Hi Guys, i have a file where data is in the below format:: data1 data2 data3 data4 data4 data6 my script written as:: #!/bin/ksh cd $1 at now <<END sh $2 END Here i want to pass the values stored in the above file one by one till the end of line. Here if i am doing it as:: (2 Replies)
Discussion started by: Atp3530
2 Replies

8. Shell Programming and Scripting

passing variable to another file and replacing

Hi all, I have a script in file1 which gets input from the user say variable "TYPE". This variable is present in the other file2. I want to replace the variable in the file2 with the value given by the user and print the file. How can I achieve this task? file1 code echo "Give... (3 Replies)
Discussion started by: Ananthdoss
3 Replies

9. Shell Programming and Scripting

passing the output of cmd from "eval" to a variable

Hello, I need help with the eval command. I have been building a lengthy cmd using eval, and I need to create $var from the output of the cmd. Here is what I have. Out=/dfezz1/output.txt Node="'LPAR Info:'" Gr3p0=" |grep" Printc=" prtconf" Output1=" 1>>$Out 0>&1" Cat1="cat... (8 Replies)
Discussion started by: dfezz1
8 Replies

10. Shell Programming and Scripting

Passing output of sed/echo to a variable

I understand how to use a variable in a sed command, but for the life of me I can't get the output into a variable. I'm making a general function to replace part of a filename with a different string, so: >>myscript this that would change: this_file001.txt to that_file001.txt and... (11 Replies)
Discussion started by: donflamenco
11 Replies
Login or Register to Ask a Question