![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
+ 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 |
|
||||
|
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 |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|