passing arguments

I'm trying to pass a filename, or all the files in the current directory to the ls command with a script. Unsuccessful so far, here are a few of my attempts:


read fname
#if (( $# > 0 )); then
$fname | ls -l

this produces a long listing of all the files in my current directory, not what I want.

So does this:


if (( $# > 0 )); then
$# | ls -l

any help?



if(test $# = 0)
then echo "please give atleast 1 arguments"
ls -l $@

usage: sname filename1 filename2 file* *

even easiest way is to create an alias of ls:
alias ls='ls -l'

Well, I have the arguments passing, but I need some help with tr. I would like to change the first - in the ls -l output to T for text file, B for binary, S for script, and so on. That part is not working yet, I plan on grepping for thingls like .java for a Java file (the - will be a J).


if (( $# > 0 )); then
ls -l $*
grep .java$ | tr '^-' 'J'


You cann't acomplish this idea by just using "tr". this needs some script work(but not difficult) :). you can use "file" command which shows you information about the file type of the files you specify.

for F in "$@"; do
file $F

and then you run this script: sname *
here is sample output:
file1: empty
Mail: Directory
test: perl commands test
dead.letter: MIME entity text
he: Executable .. gzip copressed data ...
list: ASCII text
link2: symbolic link to file1 Bourne shell script
test.c: c program text

or use:
ls -l $F|tr "\n" " "
file $F
this will print all details of a file in one line. with some script works you can make your output even better

Thanks, this works: ls -l $* | grep .java$ | sed "s/-/J/"

It produces this output:

Jrw-r--r-- 1 jprial cdgrp 15 Apr 02 12:29

That's one down, but I need to put this into a script with if statements, so
that I can grep for "empty", "commands", and other things using the file command.
I would like to check for at least one argument first, and then
a) check for file names ending in .java, .c, or .cpp
b) send the files NOT named as above to the file command
and then c) put the appropriate letter (i.e. C for c program files) in place of the dash.