Output to shell variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output to shell variable
# 1  
Old 12-03-2011
Output to shell variable

Code:
head -n 1 ~/.fvwm/config | grep -c "some-string"

It's the output from grep I need to put into a shell variable.

Also - I appreciate tips for other commands giving the same output.

Last edited by Swepter; 12-03-2011 at 12:40 AM.. Reason: typing error
# 2  
Old 12-03-2011
If you're using kshell or bash then this will work:

Code:
variable=$(head -n 1 ~/.fvwm/config | grep -c "some-string")

This User Gave Thanks to agama For This Post:
# 3  
Old 12-03-2011
Quote:
Originally Posted by agama
If you're using kshell or bash then this will work:

Code:
variable=$(head -n 1 ~/.fvwm/config | grep -c "some-string")

That worked, thank you very much.

/Swepter
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use printf to output a shell variable path?

So I created two shell variables: COLUMN1_HEADING, COLUMN2_HEADING. They have values: COLUMN1_HEADING="John" COLUMN2_HEADING="123456789" How would I use printf to get it to print an output like this: $COLUMN1_HEADING\t$COLUMN2_HEADING\nJohn\t123456789\n Thanks! (3 Replies)
Discussion started by: steezuschrist96
3 Replies

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

3. Shell Programming and Scripting

Sending sqlplus output to a shell variable

I am trying to import a sqlplus output into a shell variable but it doesnt seem to be working. set -x export DEPENDENT_CR_NO=`sqlplus -s /nolog <<EOF conn username/passwd set heading off select dependency from custom_patches where patch_name='PATCH.zip'; exit; EOF` echo $DEPENDENT_CR_NO ... (2 Replies)
Discussion started by: beginer314
2 Replies

4. Shell Programming and Scripting

Output of matlab as a variable for shell script

I'm running a matlab code within a shell script. This is how I do it, matlab -nodesktop -nosplash -nojvm -r "my_program;quit" This works fine. My matlab code prints out a single number, say "ans = 10" for example. I want to assign this to a variable in the shell script. I tried doing this... (18 Replies)
Discussion started by: lost.identity
18 Replies

5. Shell Programming and Scripting

sql output to shell variable

Hi I tried searching but I used to see , this has been answered may times. But I could not find. I am looking a SQLPLUS output to be assigned to shell variable. This is what I coded. ##/bin/ksh sqlplus dmishr/mishra#09@ps004d.world <<ENDOFSQL spool abc.log SET ECHO OFF NEWP... (4 Replies)
Discussion started by: dgmm
4 Replies

6. Shell Programming and Scripting

assigning nawk output to shell variable

Hello friends, I doing the follwing script , but found problem to store it to a shell variable. #! /bin/sh for temp in `find ./dat/vector/ -name '*.file'` do echo $temp nawk -v temp=$temp 'BEGIN{ split(temp, a,"\/"); print a}' done output: ./dat/vector/drf_all_002.file... (6 Replies)
Discussion started by: user_prady
6 Replies

7. Shell Programming and Scripting

assigning command output to a shell variable

I have the sql file cde.sql with the below contents: abcdefghij abcwhendefothers sdfghj when no one else when others wwhen%others exception when others Now I want to search for the strings containing when others together and ceck whether that does not occur more than once in the... (2 Replies)
Discussion started by: kprattip
2 Replies

8. Shell Programming and Scripting

awk redirect output to shell variable

I'm trying to redirect awk's output to a BASH variable. Currently the statement looks like this options=`awk '{ while (i < NF) { print $i; ++i } }' answer but for some reason that makes $options look like this: 1 2 3 4 1 2 3 Now, the input file 'answer' is taken from a dialog... (3 Replies)
Discussion started by: dhinge
3 Replies
Login or Register to Ask a Question