How to omit "./" store in variables

Good Morning All,

I did a find command to search for files and stored it in a variable. I then will use the variable to get the file name and "get" it from another server (using ftp). The problem I have is, filenames are stored with "./" in the variable. when I try to get it, I get an error because "./" does not work in the other server i.e. windows NT.

How do I just extract the filename without the "./" as stored in the variables.

Example :
Contents of FILES variable
./test.txt ./process.txt ./order.txt

I only want to get values of $FILES without "./".

Thanks a lot!

Add this to your script.

Suppose VARIABLE holds all the filenames that came out of the find.

RESULT=`echo $VARIABLE | sed -e 's/\.\///g'`

$RESULT should hold all the values without the ./

Havn't tested it tho'.

Vino

it worked!

Thank you very much!!!!

RESULT=`echo basename $VARIABLE`

is also a choice.

what is a basename? a built in unix function?

basename is a external command like sed. However:
RESULT=`basename $VARIABLE`
is the syntax. With modern shells, you can use builtins to do this:
x=${x#./}

Thanks!

Is it also the same if I do :

x=${x#*./}?

Another curios question. In processing variables, is it always a good practive to enclosed it with curly braces?

Thanks a lot!

Joseph
ps. What is a good unix programming book :slight_smile:

No putting in the star would not be the same. Sometimes the braces are required like in this example. Braces will never hurt. I don't use braces unless I have a reason. See our faq section for book suggestions.

Thanks! that is why I am confused. And I tried adding "*", I got the same results.

The book I am reading suggested to use "*"

ex.
$ print $PWD
/usr/home/valley
$ print ${PWD#*/}
usr/home/valley

Thanks again!

Joseph

usually
${x##*/}
is same as basename.

Just because you get the same results in one case does not mean that they are the same command. Try:
x=abc./xyz
echo ${x#./}
echo ${x#*./}