store the last part path of file in variable?
i have path for example :-
$1=/path1/path2/path3
i want to store path3
in variable
x=path3
how i can do it in :- 1-windows 2-unix
store the last part path of file in variable?
i have path for example :-
$1=/path1/path2/path3
i want to store path3
in variable
x=path3
how i can do it in :- 1-windows 2-unix
You can use either parameter expansion or the basename utility.
x=${1##*/}
x=$(basename "$1")
In Windows (shell script):
set FILE=c:\temp\test.txt
for /f %%F in ("%FILE%") do set FILE=%%~nF%%~xF
echo %FILE%