2
#!/bin/bash
FILES=src/*.erl
shopt -s nullglob
for f in $FILES
do
  echo "Processing $f file..."
# ???
done

How i can extract file name from full path? And what does it mean - "pathfilename=${f%.*}"?

1
  • 1
    Your shopt -s nullglob should be placed before you use glob *.. and it is not necessary to save the glob-list of files into a variable and then use that variable in your loop. You can simply (and more efficiently) use for f in src/*.erl Commented Oct 12, 2011 at 11:14

2 Answers 2

5

I'll just copy the help-output, since it has examples and everything.

~$ basename --help
Usage: basename NAME [SUFFIX]
  or:  basename OPTION
Print NAME with any leading directory components removed.
If specified, also remove a trailing SUFFIX.

      --help     display this help and exit
      --version  output version information and exit

Examples:
  basename /usr/bin/sort       Output "sort".
  basename include/stdio.h .h  Output "stdio".
Sign up to request clarification or add additional context in comments.

Comments

2

Update: I've removed my answer to the first part, since apparently I misunderstood what was being asked.

The syntax you mention, pathfilename=${f%.*}, means that pathfilename is set to the value of $f with the shortest possible match for .* removed from the end of the string. This will strip the extension from the filename. The bash manual describes this syntax as follows:

${parameter%word}

${parameter%%word}

Remove matching suffix pattern. The word is expanded to produce a pattern just as in pathname expansion. If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the "%" case) or the longest matching pattern (the "%%" case) deleted. If parameter is @ or *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.