3

So long story short I have to make a Shell Script where I need to have something like two variables, the first one contains a path read from the keyboard (something like:this/is/the/path/I/need)

I really need to extract the last folder of that path example, and put it in another variable, in my example I need to get out of the path the "need" part and put it in the second variable. How can I do this? The fact that this is read from the keyboard makes it pretty hard to do in my opinion. Thanks!

123123d
  • 195
  • 2
  • 14

1 Answers1

3
$ read path
this/is/the/path/I/need
$ directory=$(basename $path)
$ echo $directory
need
$
jvdm
  • 846
  • 6
  • 22