Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

fileName=${npFile##/*/}
share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

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`
share|improve this answer
add comment

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"

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.