Assigning output of command to a variable in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assigning output of command to a variable in shell
# 1  
Old 02-28-2008
Assigning output of command to a variable in shell

hi,
I want to assign find command result into some temporary variable:

jarPath= find /opt/lotus/notes/ -name $jarFile
cho "the jar path $jarPath"

where jarPath is temporary variable.

Can anybody help on this.

Thanks in advance
----Sankar
# 2  
Old 02-28-2008
jarPath=`find /opt/lotus/notes/ -name $jarFile`
echo "the jar path $jarPath"
# 3  
Old 02-28-2008
Quote:
Originally Posted by manikantants
jarPath=`find /opt/lotus/notes/ -name $jarFile`
echo "the jar path $jarPath"

Hi,
Its not working...See i have written this code in some file called Notes.start

from bash i run like that ./Notes.start

its not giving any output....


Is there any constraints on different shell.I want to run the same file in AIX/Solaris/unix/linux.

and i am new this unix..

-sankar
# 4  
Old 02-28-2008
this should work provided following are correct

Under /opt/lotus/notes/, there should be a file or directory with name in variable '$jarFile'.

Can you run the script in debug mode ? (give 'set -x' in the begining of the script) and paste the result here ?
# 5  
Old 02-28-2008
Quote:
Originally Posted by manikantants
this should work provided following are correct

Under /opt/lotus/notes/, there should be a file or directory with name in variable '$jarFile'.

Can you run the script in debug mode ? (give 'set -x' in the begining of the script) and paste the result here ?



file Name :::Notes_debug.start

set -x
jarFile=Notes.jar
if [ -f "$jarFile" ]; then
jarPath=`pwd`
fi
if [ $jarPath="" ]; then
jarPath= find /opt/lotus/notes/ -name $jarFile
echo "the jar path $jarPath"
fi


Output

+ jarFile=Notes.jar
+ [ -f Notes.jar ]
+ [ = ]
+ find /opt/lotus/notes/ -name Notes.jar
+ jarPath=
/opt/lotus/notes/65040/ibmpow/Notes.jar
+ echo the jar path
the jar path
# 6  
Old 02-28-2008
In your script, i can see jarPath= find /opt/lotus/notes/ -name $jarFile
As I told you before please change this line to jarPath=`find /opt/lotus/notes/ -name $jarFile`


notice the backtick (backtick is with the tild key)
# 7  
Old 02-28-2008
set -x


jarFile=Notes.jar



if [ -f "$jarFile" ]; then
jarPath=`pwd`
fi


if [ $jarPath="" ]; then
jarPath= `find /opt/lotus/notes/ -name $jarFile`
echo "the jar path $jarPath"
fi





+ jarFile=Notes.jar
+ [ -f Notes.jar ]
+ [ = ]
+ find /opt/lotus/notes/ -name Notes.jar
+ /opt/lotus/notes/65040/ibmpow/Notes.jar
+ jarPath=
/opt/lotus/notes/65040/ibmpow/Notes.jar: PK^C^D: not found.
/opt/lotus/notes/65040/ibmpow/Notes.jar[2]: ^X^U: not found.
/opt/lotus/notes/65040/ibmpow/Notes.jar[2]: 2: not found.
A file or directory in the path name does not exist.
/opt/lotus/notes/65040/ibmpow/Notes.jar[3]: ^Y^U: not found.
/opt/lotus/notes/65040/ibmpow/Notes.jar[3]: ^TMETA-INF/MANIFEST.MFManifest-Version:: 0403-005 Cannot create the specified file.
/opt/lotus/notes/65040/ibmpow/Notes.jar[4]: 0403-057 Syntax error at line 4 : `(' is not expected.
+ echo the jar path
the jar path
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect - assigning UNIX command output to a variable

Hi, I'm writing a script that connects through ssh (using "expect") and then is supposed to find whether a process on that remote machine is running or not. Here's my code (user, host and password are obviously replaced with real values in actual script): #!/usr/bin/expect set timeout 1... (3 Replies)
Discussion started by: oseri
3 Replies

2. UNIX for Dummies Questions & Answers

Tcsh command for assigning output of awk to variable

Hi I have a text file with 2 values and I am trying to assign each value to a variable and then write those to text files. So if the textfile is data.txt with 2 values x and y I want to assign mean=x, and stdev=y and then write these out in text files alongwith the id ($id has already been... (6 Replies)
Discussion started by: violin
6 Replies

3. UNIX for Dummies Questions & Answers

Assigning the output of a command to a variable, where there may be >1 line returned?

Hello I am using unix CLI commands for the Synergy CM software. The command basically searches for a folder ID and returns the names of the projects the folder sits in. The result is assigned to a variable: FIND_USE=`ccm folder -fu -u -f "%name"-"%version" ${FOLDER_ID}` When the command... (6 Replies)
Discussion started by: Glyn_Mo
6 Replies

4. Shell Programming and Scripting

Assigning value of SQL output to a variable in shell scripting

I am trying to assgn the output of the select statement to a variable, like this "VARIABLE_NAME=$ db2 "select COLUMN_NAME_1 from TABLE_NAME where COLUMN_NAME_2='VALUE_TO_CHECK'"; " but the value that is getting into VARIABLE_NAME is "COLUMN_NAME_1 ----------------- VALUE 1... (3 Replies)
Discussion started by: sgmini
3 Replies

5. Shell Programming and Scripting

Assigning variable from command outputs to shell

First, this is bash (3.2.17), on a Mac, 10.5.7. What I'm trying to do is look at a list of users, and check to see if each exists. If they do, do some more stuff, if they don't, drop them into an error file. So, my user list is: foo - exists bar - does not exist blah - does not exist ... (2 Replies)
Discussion started by: staze
2 Replies

6. Shell Programming and Scripting

Assigning output of a command to variable

When I run time -p <command>, it outputs: real X.XX user X.XX sys X.XXwhere X.XX is seconds. How I can take just that first number output, the seconds of real time, and assign that to a variable? (9 Replies)
Discussion started by: jeriryan87
9 Replies

7. Shell Programming and Scripting

Assigning output to a variable

I am new to unix shell scripting. I was trying to convert each lines in a file to upper case. I know how to convert the whole file. But here i have to do line by line. I am getting it in the below mentioned script #!/bin/bash #converting lower to upper in a file #tr "" "" <file1... (3 Replies)
Discussion started by: jpmena
3 Replies

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

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

10. Shell Programming and Scripting

Assigning output of command to a variable

Hi, I'm trying to assign the output of a command to a variable and then concat it with another string, however, it keeps overwriting the original string instead of adding on to the end of the string. Contents of test.txt --> This is a test var1="`head -n 1 test.txt`" echo $var1 (This is a... (5 Replies)
Discussion started by: oma04
5 Replies
Login or Register to Ask a Question