I am writing a shell script in which I have to separate the file name and file path from a complete file path.  For example /home/loneranger/Documents/test/file.dat is the complete path. I want to separate name and Path and put them in variables.   So far I am able to separate file name by using basename command. 
file_name =$(basename $path) 
file_location =`echo $path | sed 's/$file_name//' `
But the sed command is not working. It's working when I execute it outside in command line by replacing the file_name by file.dat. Not sure why it's behaving this way. Can somebody explain.
PS: Sorry for poor formatting as I am typing from a mobile device.