How to list filenames with spaces in shell script

Hi,

I want to list all the files matching in a directory directory given below
Here one of the folder has a space in the path.

/MAS02/RMS/WBDev/Krishna/Krishna Mohan/FMSplitByKeyAfterChanges1000075383.fileman.*.txt.out.1000075383.0

The following works from command line
********************************

ls '/MAS02/RMS/WBDev/Krishna/Krishna Mohan/'FMSplitByKeyAfterChanges1000075383.fileman.*.txt.out.1000075383.0

I am trying to do the same stuff from shell script ,but it is not working.
Pls suggest
********

#!/bin/ksh -x
#
in="/MAS02/RMS/WBDev/Krishna/Krishna Mohan/FMSplitByKeyAfterChanges1000075383.fileman.*.txt.out.1000075383.0"
dirName=`dirname "$in"`
fileName=`basename "$in"`
newfileslist=\'$dirName/\'$fileName
filecnt=`ls $newfileslist | wc -l `

It gives an error like this, when I execute above script
****************************************

+ ls /MAS02/RMS/WBDev/Krishna/Krishna Mohan/FMSplitByKeyAfterChanges1000075383.fileman..txt.out.1000075383.0
+ wc -l
ls: /MAS02/RMS/WBDev/Krishna/Krishna: No such file or directory
ls: Mohan/FMSplitByKeyAfterChanges1000075383.fileman.
.txt.out.1000075383.0: No such file or directory
+ fcnt=0

in="file with space"
d_var=$(dirname "$in")

Not sure the syntax on your dirname. (It is giving me errors) However, try this other way of assigning a value.

But, you want to make sure to enclose variables with space characters inside the " double quotes. Especially when consecutive spaces, as there is a natural trim function with echo command.