1832657 Members
3116 Online
110043 Solutions
New Discussion

Re: Using for

 
SOLVED
Go to solution
Leo The Cat
Regular Advisor

Using for

Hello

I've to provide a list of filenames with a for command, something like that below.

for file in /su01/upload/* ; do
echo $file;
done

This works perfectly but i'd like to have only the filename not
/su01/upload/filename1
/su01/upload/filename2
....

How to have only
filename1
filename2
...

Bests Regards
Den
4 REPLIES 4
Pete Randall
Outstanding Contributor
Solution

Re: Using for

Den

Simple:

cd /su01/upload
for file in *
do
echo $file
done


Pete

Pete
Leo The Cat
Regular Advisor

Re: Using for

Of course. sorry ! Thanks Pete
James R. Ferguson
Acclaimed Contributor

Re: Using for

Hi Den:

You want the basename of the file. YOu can get this with:

# file=/home/den/myfile
# echo $(basename ${file})
myfile

...or more economically using the shell only:

# echo ${file##*/}
myfile

Regards!

...JRF...
Leo The Cat
Regular Advisor

Re: Using for

Pete answer is .... very good !