How to combine two variable strings?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to combine two variable strings?
# 1  
Old 02-28-2013
How to combine two variable strings?

Hi,

I have two variables

Code:
 
pscmd="ps -exf | grep "
 
pid=15560

When I say

Code:
 
var=$( $pscmd $pid )
echo $var

it shows output of all processes on the OS rather than just 15560.

So, i guess it only executes "ps -exf | grep " rather than "ps -exf | grep 15560"

Can you please let me know whats wrong ?

I'm on HP -UX
# 2  
Old 02-28-2013
Code:
var=$( eval "$pscmd $pid" )

# 3  
Old 02-28-2013
This may work
Code:
var=$(ps -exf | grep $pid)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to get multiple strings in one variable

I am processing a file using awk to get few input variables which I'll use later in my script. I am learning to script using awk so please advise in any mistakes I made in my code. File sample is as follows # cat junk1.jnk Folder1 : test_file (File) ... (5 Replies)
Discussion started by: shunya
5 Replies

2. UNIX for Beginners Questions & Answers

Can I combine below mentioned grep commands using OR (when searching strings having spaces)

Command 1: $script | grep 'Write to ECC( SSID=MARGIN)' Command 2: $script | grep 'is not greater than existing logical processing' The above commands run my script and search the mentioned strings but I do not want to run my script twice. It is increasing run time. Can someone tell me... (3 Replies)
Discussion started by: Tanu
3 Replies

3. Shell Programming and Scripting

Need help with using strings in variable

Hi, I am calling a in-house built api from unix shell script for posting some comments on jira. Facing some problem in handling variables could someone give some insights here. #1) Below is working I have declared a variable called var=testing and used that var in my api it works fine. ... (1 Reply)
Discussion started by: close2jai
1 Replies

4. Shell Programming and Scripting

Combine identical lines and average the one variable field

I have the following file 299899 chrX_299716_300082 196 78.2903 299991 chrX_299982_300000 18.2538 Tajd:0.745591 FayWu:-0.245701 T2:1.45 299899 chrX_299716_300082 196 78.2903 299991 chrX_299982_300000 18.2538 Tajd:0.745591 FayWu:-0.245701 T2:0.283 311027 chrX_310892_311162 300 91.6452... (2 Replies)
Discussion started by: jfern
2 Replies

5. Shell Programming and Scripting

How to combine two variable result?

Hi, i have two variables i.e lck_ckm_customer=ckm_customer and(present in some script A) table=ckm_customer(present in script B) in script B i am executing this part if ; then --- ---- ---- fi Now, while comparing in my log file i am getting this result if but i... (2 Replies)
Discussion started by: gnnsprapa
2 Replies

6. Shell Programming and Scripting

Combine 2 values into single variable

Hi gurus, I need to manipulate the output of a database query. The output contains 2 fields (asset and serial number) and I'd like to combine them into a single value, seperated by whitespace. the orginal data is in seprate fileds and of the following format: asset serial asset serial etc ... (6 Replies)
Discussion started by: melias
6 Replies

7. Shell Programming and Scripting

Perl removing strings from a variable value

Dear all, I have a variable called $abc, which the value is something like below, *** *********** : ***** where * can be anything. I need to remove all but the final characters until last whitespace. example grd groupstudy : tutor6/7 becomes tutor6/7 something like if... (2 Replies)
Discussion started by: tententen
2 Replies

8. Shell Programming and Scripting

Deciphering strings or variable values

Hi, I have a script at the moment of which reads in simply what the latest version is within a folder i.e. v001, v002, v003 etc and then stores this latest version in a variable i.e. $LATEST would echo v003. I have then cut this string so that I only consider the 003 part. I would then like to... (3 Replies)
Discussion started by: cyberfrog
3 Replies

9. Shell Programming and Scripting

combine data of 2 files by variable

my first post ... please be gentle. I have been working on a script to get info out of mysql. Its a support ticket system database OTRS. I can write the subject of open tickets to a text file with a unique user id. I also have a text file with the unique user id, username and email adres. I... (11 Replies)
Discussion started by: dicenl
11 Replies

10. Shell Programming and Scripting

appending strings to variable

is it possible? as i keep reading a file, i want one particular variable to keep storing the line that i've read so far (1 Reply)
Discussion started by: finalight
1 Replies
Login or Register to Ask a Question