2015-11-05 94 views
1

只需要做一个Shell脚本,我需要有两个变量,第一个包含从键盘读取的路径(如下所示: this/is/the/path/I/needLinux Shell脚本剪掉包含路径的变量的最后一部分

我真的需要提取该路径示例的最后一个文件夹,并将其放入另一个变量中,在我的示例中,我需要摆脱“需要”部分的路径并将其放入第二个变量中。我怎样才能做到这一点?这是从键盘读取的事实,使我很难做到我的意见。谢谢!

回答

3
$ read path 
this/is/the/path/I/need 
$ directory=$(basename $path) 
$ echo $directory 
need 
$