List Files script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List Files script
# 1  
Old 10-29-2013
List Files script

Hello everyone - I have the task to create a file list script that will list files in directory based on the parameters passed to the program.
It has to be a C Shell - I mentioned that before but I got closed Smilie - the company only allows this shell for security purposes I guess.

Anyway, here is the code I am trying to run:
# List files from
# current directory
set command = `ls`
set i = 1
while ($i <= $#argv)
 switch ($argv[i])
  case "l":
       echo `ls -l`
       echo $command;
@ i = $i + 1

If I run the program with no parameters passed nothing happens - no echo.
If I pass "l" then I get an error " Missing -."

Is there a typo in the code that I cannot see?
Thank you.

Last edited by jim mcnamara; 10-29-2013 at 08:23 AM.. Reason: icode to code tags
# 2  
Old 10-29-2013
Your previous thread was closed because you mentionned it was a university box and talked about assignement, if this is some assignement or homework please ask to close it and post in the adequate forum following the rules that are there,, if you say its not but we find out it is you will quite surely be banned, what makes our thread a bit suspicious is the need of c-shell which is moslty used in colleges or universities when most of them had sparcstations with SunOS ( 4? )... ( there has been some evolution since hehe...), I am trying to understand what can it be for security reasons...
# 3  
Old 10-29-2013
It has to do with test vs production.
Our IT will not allow any testing in production environment - that is why we have a box, "university" box laying around that we can use to mess around with Linux - big, bulky gray machine, it may be a Sun server as you mentioned.
Once we get our testing completed we will submit to them and they will move it to production on their box - why C? Good question but I don't have an answer - not the Linux guy.
Regardless - don't worry about it. I think you should give the user the chance to explain something before closing a thread.

Thank you for the help with the previous post.
# 4  
Old 10-29-2013
set command = `ls`
set i = 1
while ($i <= $#argv)

OK you set command to a list produced by ls, but where is argv going to get the result? since its a positional parameter it expects them as such...
so for me $#argv = 0...
# 5  
Old 10-29-2013
Well the issue was an error message i.e. "Missing -."
It had to do with spelling. I wrote
switch ($argv[i]) and it should be switch ($argv[$i])

Works now - thank you again.
I'll try to be more specific next time Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create a list of files from alias by script

Actually I have many pictures with diferent name and size around 2000, I need generate a copy of them from one list of alias. The structure of the list is something like this: alias_list.txt <01>randomname.png<02> Randomname.png RandoMname.png RandOmname.png RandomnamE.png... (6 Replies)
Discussion started by: Tapiocapioca
6 Replies

2. UNIX for Beginners Questions & Answers

List Files being deleted in a shell script

Good evening, i need your help please I've got a file script thet deletes about half millions of files, and i want those files to be printed in a log file as an evidence those files were removed. #/bin/sh rm "/home/e-smith/files/users/bill/Maildir/cur/1392373930.28512.comp01:2,S" rm... (6 Replies)
Discussion started by: alexcol
6 Replies

3. UNIX for Dummies Questions & Answers

Awk/script to list the owners of files

I have to list the files in a directory and along with that, list the owner of each of those files. Can someone please help me with a way to get this info please? Gayathri (2 Replies)
Discussion started by: ggayathri
2 Replies

4. UNIX for Dummies Questions & Answers

Script to list non matching files using pattern

Hi, I am trying to write a script that list down all the files that do not match the pattern My pattern will be like this "*.jpg|*.xml|*.sql". This pattern will be stored in a file. The script need to read this pattern from the file and delete the files that does not match this pattern. It... (7 Replies)
Discussion started by: meenavin
7 Replies

5. Shell Programming and Scripting

A perl script to list files

Hi guys, I'm learning grep and map functions in perl and ran into a problem. I have a little script below: #!/usr/bin/perl -w die "Usage: $0 dir\n" if @ARGV != 1; opendir (D, $ARGV) or die $!; @text_files = grep { !-d } readdir D; rewinddir D; @sizes = sort {$b <=> $a} map { -s... (7 Replies)
Discussion started by: new bie
7 Replies

6. Shell Programming and Scripting

How to process list of files as array in the script

Hi., In my script I have written : file_list=`ls -lrt /tmp/vinay/act/files |grep "$cdate"| awk '{print $9}'` To store list of files in the directory. Now I want to access it as list. And for this I tried with : set -A filearray $file_list if }` == "" ]]; then ... (1 Reply)
Discussion started by: IND123
1 Replies

7. Shell Programming and Scripting

I need a script to find socials in files and output a list of those files

I am trying to find socail security numbers in files in (and under) a specific directory and output a list of the files where they are found... the format would be with no dashes just 9 numeric characters in a row. I have tried this: find /DirToLookIn -exec grep '\{9\}' /dev/null {} \; >>... (1 Reply)
Discussion started by: NewSolarisAdmin
1 Replies

8. Shell Programming and Scripting

Getting a list of files on an ftp, via shell script...

G'day, I was wanting to write a shell script that checks an ftp server for the presence of new files, then get those files. In so much as the get, this is pretty straight forward, but I cannot work out how to get a list of files to check. Is it possible for a shell script to get the output of... (1 Reply)
Discussion started by: Elric of Grans
1 Replies

9. UNIX for Dummies Questions & Answers

help to make list of files and run script..

Hey, I have finally made a command that works and now has to run it on 200+ files to run it on. How do I do that? Just fyi and if it complicates anything my commandline is: awk '{if ($1 ~ /1/) print $2}' file (yup, is should print $2 if $1 is a certain value) It doesn't work when I: ... (2 Replies)
Discussion started by: lost
2 Replies

10. Shell Programming and Scripting

Reading list of files into ftp script

How can I go about getting this done? I have tried and failed with a loop before I start the session and after seeing that I am already in the ftp code block and not bash when I am trying to perform this: #FTP Information ftp_user=xxxx while read line; do... (1 Reply)
Discussion started by: BkontheShell718
1 Replies
Login or Register to Ask a Question