How to cut a string from a variable
Hi,
Say suppose "directory/files/file.h" path is saved in a variable. How can i get the file name i.e "file.h" from the above path Want the file name separetly. Please help me... |
You can use bash internals to do just that:
Code:
$ fname="directory/files/file.h" EDIT: If bash cannot be used, try using the basename command: Code:
$ basename $fname |
basename works!!
Thanks :) Is there any way i can get the path of that file "file.h" Thanks in advance. |
basename - Strip directory and suffix from filename
dirname - strip last component from filename Code:
dirname $fname Code:
info bash |
Or the equivalent of # being %:
Code:
$ fname="directory/files/file.h" |
All times are GMT -5. The time now is 09:25 PM. |