C shell script help!!

InuYasha

Senior member
Mar 21, 2001
236
0
0
I need help with 2 scripts i'm doing

1) Write a script that will list the files you have in the current
directory, followed by the directories. The output should have the
form:

Files:
------
filenames

Directories:
------------
directories


2) Write a script that will take two command line arguments (not inputs).
These two arguments specify an old file extension and a new
file extension. The script should rename all the files in the current
working directory to ones with the new extension.

e.g. script3 doc tex

should change all files with having the extension .doc to have the
.tex extension.


I'm clueless on doing this since i'm a n00b on Shell scripts, help!!
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
You say "C shell script". Do you mean you're writing this in C, or you want a true shell script? These are awfully different things. If you want a shell script, which shell? If you're doing this in C, which platform?

For linux, look up the ftw() function.

For Windows, look up the FindFirstFile() function.

If you provide additional details as well as samples of your attempts to actually do your homework yourself, I'm sure we can help you further :D

[edit]Also look at opendir()/readdir()[/edit]
 

InuYasha

Senior member
Mar 21, 2001
236
0
0
well, fine, does anyone know how to list ONLY directories in UNIX? someone told me it's the ls command, but I cant get it to show only directories without the files.
 

ElDonAntonio

Senior member
Aug 4, 2001
967
0
0
type:

man ls

at the command prompt. You'll get all the options and switches regarding the ls command.

Good luck!
 

CodeJockey

Member
May 1, 2001
177
0
0


<< You say "C shell script". Do you mean you're writing this in C, or you want a true shell script? These are awfully different things. If you want a shell script, which shell? If you're doing this in C, which platform? >>



The "C Shell" is csh, as opposed to the "Korn Shell" (ksh), or the "Bourne Shell" (bsh). It is significant, sometimes, since each shell has different built-in functionality that can help or hinder your efforts to write a script.

To ensure that you use the C Shell, the first line of your script should be:
#!/bin/csh

OK, I've got you started...the rest is up to you. :)

BTW, If ls doesn't have options to list only files and only directories, you can use awk to filter the output from ls in order to have it select and output only the lines you want. There are probably six other ways to do this, also (sed or grep may be able to handle the task).