I think this is enough:
filenamepath="/caminho/para/ficheiro.pdf"
filepath=${filenamepath%/*}
Note: because it is a parameter treatment of bash, is not "portable" to any shell.
If you prefer a solution analogous to the question, using external commands, we have the dirname, which is the "natural pair" of basename:
filenamepath="/caminho/para/ficheiro.pdf"
filename=$(dirname $filenamepath)
Alternatively, here is a syntax using the sed and demonstrating the use of backticks to pick up the output of another command:
filenamepath="/caminho/para/ficheiro.pdf"
filepath=`echo $filenamepath | sed 's|\(.*\)/.*|\1|' `