How do i get just the last name in linux path name?



  • In shell scripting, you sometimes just want the last name in the path, to achieve this we can use the basename command.

    We have a path /usr/local/pycharm/index, we just need to use the "index" part in the script.

    See what it does on the command line.

    $ basename /usr/local/pycharm/index
    

    Using it in the script, you may assign the path to a variable and use the variable name.

    ...
    ...
    Pycharm_Index=/usr/local/pycharm/index
    Pycharm_Index_Base=$( basename $Pycharm_Index)
    echo $Pycharm_Index_Base
    ...
    ...
    

Log in to reply
 

© Lightnetics 2024