1

What does the following shell script mean? This is ksh and npfile is also a variable that contains a file name.

fileName=${npFile##/*/}
C. Ross
  • 3,075
  • 9
  • 35
  • 36

2 Answers2

4

It strips the base off of the path to the file. In variable expansion, ## means "take the thing to my right, treat it as a pattern, and delete the longest match of it in the variable to my left."

In this case the pattern is /*/, so the longest match of that in a variable which included a path and filename would be the path. Deleting it would leave only the filename.

It appears to be a variable-expansion-only way of writing this:

filename=`basename $npFile`
jj33
  • 11,178
  • 1
  • 37
  • 50
1

That trims "/*/" (everything from the first slash to the last slash) from the beginning of the string.

So if npFile="/path/to/file" - fineName would become "file"

Brent
  • 22,857
  • 19
  • 70
  • 102