Thanks Derokorian and Johanafm,
I am still struggling with this shell_exec call from php.
I am being more specific with the following code. I am generating these variables in my code and that is why I am using these variables.
<?php
print(shell_exec('/bin/bash -c "ls -l"'));
$dir = '/home/tmpDir';
$idx1 = 1;
$idx2 = 2;
$idx3 = 3;
$idx4 = 4;
$inpfile= 'file.txt';
$outfile= 'fileout.txt';
$bash = '/bin/bash';
$part1 = 'awk -vOFS="\t" ' . '\'{$'.$idx4. '=$'.$idx1.'"_"$'.$idx2.'"_"$'.$idx3.'}NR==1{$'.$idx4.'='. '"name"}1\'';
$command1 = $part1. ' '. $dir. '/'.$inpfile . " > " . $dir. '/'.$outfile;
print($command1); //This command works fine on command line.
print("<br><br>");
$command2 = $bash. ' -c "'.$command1. '"';
print($command2);
shell_exec($command2);
?>
Following are the output of the above file.
awk -vOFS="\t" '{$4=$1""$2""$3}NR==1{$4="name"}1' /home/tmpDir/file.txt > /home/tmpDir/fileout.txt
/bin/bash -c "awk -vOFS="\t" '{$4=$1""$2""$3}NR==1{$4="name"}1' /home/tmpDir/file.txt > /home/tmpDir/fileout.txt"
The first command 'command1' works well on shell prompt. Somehow I want to embed them into double quotes as I did in the first line of the php script to print list of files. Upto now I remained unsuccessful.
Thanks.