Create variables from directory list problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create variables from directory list problem
# 1  
Old 06-01-2010
Create variables from directory list problem

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 Code:
<?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:
Code:
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.

Last edited by Franklin52; 06-01-2010 at 03:00 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to create variables to pass into a bash loop to create a download link

I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Discussion started by: cmccabe
8 Replies

2. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

3. UNIX for Dummies Questions & Answers

Need help how to create a file (xml) list all files from directory

I have more than 10K songs in two directories on a hard drive. I would like to create a file list all of files name then change to .xml extension to upload to iPhone so I have a Karaoke list on my iPhone. I need your help to create a file by using command in Linux. Files names: 0001 More... (4 Replies)
Discussion started by: ggcc
4 Replies

4. Solaris

Problem when I try to create a directory on Solaris 8

Dear Gurus of solaris I have a problem when I try to create a directory when I enter in the /home/ directory and try to create a new directory appear the following error Why If I am root, Can any guru can help me (3 Replies)
Discussion started by: andresguillen
3 Replies

5. Homework & Coursework Questions

Create script to add user and create directory

first off let me introduce myself. My name is Eric and I am new to linux, I am taking an advanced linux administration class and we are tasked with creating a script to add new users that anyone can run, has to check for the existence of a directory. if the directory does not exist then it has... (12 Replies)
Discussion started by: pbhound
12 Replies

6. Shell Programming and Scripting

Create a list of directory contents

Well I did a search and didn't anything for my specific case. I got a directory with a bunch of text file. All of them have the following pattern on the filename "ABCD_<As of Date>.txt" Example: ABCD_20110301.txt ABCD_20110302.txt ABCD_20110303.txt All I want to accomplish is a Korn... (3 Replies)
Discussion started by: Shark Tek
3 Replies

7. Shell Programming and Scripting

how to create and access a directory in the same script using variables

I have a working script that defines the paths using variables which is used to move a rename files that are being archived. Is there a way to create a directory in the path with the date as the name and then reference it when moving the file to it? Here is what I have tried with no luck.... ... (1 Reply)
Discussion started by: Snickyt0310
1 Replies

8. Shell Programming and Scripting

How to create multiple list of files in a directory ?

Hi, i have say 100 files in a directory. file1.log file2.log file3.log file4.log file5.log file6.log ... ... ... file99.log file100.log ========= I need to create another file which contains the list of al these log files. each file should contain only 10 log file names. it shud... (4 Replies)
Discussion started by: robinbannis
4 Replies

9. Shell Programming and Scripting

Newbie problem with simple script to create a directory

script is: dirname= "$(date +%b%d)_$(date +%H%M)" mkdir $dirname should create a directory named Nov4_ Instead I get the following returned: root@dchs-pint-001:/=>./test1 ./test1: Nov04_0736: not found. Usage: mkdir Directory ... root@dchs-pint-001:/=> TOO easy, but what am I... (2 Replies)
Discussion started by: gwfay
2 Replies
Login or Register to Ask a Question