LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to split the file name from the path in BASH? (https://www.linuxquestions.org/questions/programming-9/how-to-split-the-file-name-from-the-path-in-bash-716064/)

jmcejuela 04-01-2009 09:48 AM

How to split the file name from the path in BASH?
 
What's the easiest way to obtain the file name and the path in 2 independent strings in a command like:

rm /path/file

so

string1=/path
string2=file

How the bash commands do it?


Thank you for your time

Sergei Steshenko 04-01-2009 09:49 AM

dirname

jmcejuela 04-01-2009 09:51 AM

OK, I guess it's simple done with dirname and basename :P

Hobbletoe 04-01-2009 10:39 AM

Or, if you have it stored in a variable such as ${a} (for lack of a better name), you can get the directory and the file using ...

Code:

dir=${a%/*}
file=${a##*/}



All times are GMT -5. The time now is 10:27 PM.