0

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

Mohammad AL-Rawabdeh
  • 1,612
  • 12
  • 33
  • 54

2 Answers2

5

You can use either parameter expansion or the basename utility.

x=${1##*/}

x=$(basename "$1")
Juliano
  • 5,512
  • 28
  • 28
0

In Windows (shell script):

set FILE=c:\temp\test.txt
for /f %%F in ("%FILE%") do set FILE=%%~nF%%~xF
echo %FILE%
Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
Simon Catlin
  • 5,232
  • 3
  • 17
  • 20