1

I am using following php code.

$i = "1TEN";
$val=exec('cat '$i'.dssp -n | grep " ACC " | grep "[0-9]\+" -o | head -n 1');
echo $val;

It doesn't give any error or any output. However, following code works well:

$val=exec('cat 1TEN.dssp -n | grep " ACC " | grep "[0-9]\+" -o | head -n 1');
echo $val;

Can anyone help ?

Similarly,

$line=exec("tail $i.dssp -n $diff | awk -F" " -v var=$pos '{if ($2==var) print FNR}");
1
  • them quotes look weird Commented May 18, 2014 at 23:31

2 Answers 2

2

You are receiving this mistake because you are inserting variable in a string in a wrong way – you should use double quotes " to specify your string and escape " in a text with \ so it won't be interpreted as the end of a string:

$val = exec("cat {$i}.dssp -n | grep \" ACC \" | grep \"[0-9]\+\" -o | head -n 1");

or use use double quotes " to specify your string and replace " in text with single quotes':

$val = exec("cat {$i}.dssp -n | grep ' ACC ' | grep '[0-9]\+' -o | head -n 1"); 

If you want to use single quotes ' you can concatenate you string like it is shown below :

$val = exec('cat ' . $i . ' .dssp -n | grep " ACC " | grep "[0-9]\+" -o | head -n 1');
Sign up to request clarification or add additional context in comments.

6 Comments

I have a similar problem in following line: $line=exec("tail {$i}.dssp -n {$diff} | awk -F\" \" -v var={$pos} '{if ({$pos}==var) print FNR}");
YES Thanks.. But I am still having problem with the following one: $line=exec("tail {$i}.dssp -n {$diff} | awk -F\" \" -v var={$pos} '{if ({$pos}==var) print FNR}"); Whats the problem in this one ?
@Om Shiv: Is if ({$pos}==var) print FNR for shell or for php to evaluate?
Its an awk command which i need to evaluate using PHP script file.
@Om Shiv : you should escape curly braces like \\{ and \\}
|
0

Use double quotes on the outside to allow variable interpolation, and use single quotes on the inside.

$val=exec("cat $i.dssp -n | grep ' ACC ' | grep '[0-9]\+' -o | head -n 1");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.