I want to make a shell script that receives a filename with its full path, for example /home/42/arquivoEscolhido.txt
, and extract only the file name ( arquivoEscolhido.txt
), which would be everything after the last slash ( /
), taking into account that the file name can always change.
I came up with something like this but it did not work:
echo -n 'Informe o arquivo: '
read dir #/home/42/teste.txt
arq=${dir#*/}