Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
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

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

Your Answer


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.