The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing in arguments into a file using a loop eltinator Shell Programming and Scripting 11 04-14-2008 04:01 PM
passing strings as arguments iago UNIX for Dummies Questions & Answers 1 08-22-2007 10:04 AM
Passing and using arguments in Scripts. David.Vilmain Shell Programming and Scripting 1 11-13-2006 05:32 PM
Passing arguments to a script Kevin Pryke Shell Programming and Scripting 3 06-14-2002 09:06 AM
Passing arguments to an alias pmcg UNIX for Dummies Questions & Answers 1 10-23-2001 11:15 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-01-2001
jpprial jpprial is offline
Registered User
  
 

Join Date: Feb 2001
Location: San Francisco
Posts: 30
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:

#!/bin/ksh

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

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

So does this:

#!/bin/ksh

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

any help?

thanks
  #2 (permalink)  
Old 04-02-2001
mib mib is offline
Registered User
  
 

Join Date: Jan 2001
Location: Calicut
Posts: 228
#!/bin/bash

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

usage: sname filename1 filename2 file* *

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

  #3 (permalink)  
Old 04-02-2001
jpprial jpprial is offline
Registered User
  
 

Join Date: Feb 2001
Location: San Francisco
Posts: 30
+ tr

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).

#!/bin/ksh

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

fi

  #4 (permalink)  
Old 04-03-2001
mib mib is offline
Registered User
  
 

Join Date: Jan 2001
Location: Calicut
Posts: 228
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.

#!/bin/bash
for F in "$@"; do
file $F
done

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 ..
he.zip: gzip copressed data ...
list: ASCII text
link2: symbolic link to file1
test.sh: 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

  #5 (permalink)  
Old 04-03-2001
jpprial jpprial is offline
Registered User
  
 

Join Date: Feb 2001
Location: San Francisco
Posts: 30
adding "ifs"

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 new.java

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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0