Say I have these files in my folder below mydir
file1.txt
file2.txt
file3.txt
file4.txt.mdgg
I want to get file name with full path, file name only and file name without path and .txt extension. For this I tried, but doesn't seem to work. Can someone please suggest me what is wrong with my code?
mydir="/home/path"
for file in "${mydir}/"*.txt; do
# full path to txt
mdlocation="${file}"
echo ${mdlocation}
#file name of txt (without path)
filename="$(basename -- "$file")"
echo ${filename}
#file name of txt file (without path and .txt extension)
base="$(echo "$filename" | cut -f 1 -d '.')"
echo ${base}
done
mdlocation="${file}" echo ${mdlocation}echo `realpath ${file}`to get absolute path for first case.