I am trying to take a list of directories in a folder and give them a variable name. I have this working with the exception that the shell_exec command wants to place a return. Here is my code which might explain better what I am trying to do: <?php session_start(); $student1=$_SESSION['student1']; $week1=shell_exec("ls /var/www/sad/ | grep 201 | awk 'NR>1{exit};1'"); $page = shell_exec("cat /var/www/sad/$week1/$student1/$student1.html"); echo "<pre>$page</pre>"; ?> I am not going to go into why I am trying to do this, but what ends up happening is the script tries to cat /var/www/sad/$week1 only because for some reason a return is held within the $week1 variable and it causes the script to treat /var/www/sad/$week1 and then $student1/$student1.html separately. and I can't seem to figure out how to alleviate this problem. I have tried: ls /var/www/sad/ | head -1 | awk '{sub(/[ \t]+$/, "")};1' ls /var/www/sad/ | head -1 ls /var/www/sad/ | awk 'NR < 2' Everything places a return at the end of the string I am asking for. Any help is greatly appreciated.