0

Using myscript mydir/* I don't understand why bash is processing only the first element with the code below.

#!/bin/bash

files="$1"

for f in "$files"; do
  echo "Processing $f"
done

What do I miss so that I can process a list of files given as an argument to the script?

Marc
  • 189
  • 1
  • 9
  • I don't think that question answer's Marc's question but I think this one does: https://stackoverflow.com/q/13519442/14079207 – 7koFnMiP Aug 17 '20 at 09:55
  • 1
    @Marc: `files` contains a single string (the first argument to your program), and the argument list of your `for ... in` also contains only a single string (the content of `files`). Hence the loop will be executed exactly once. If you want to iterate over all the arguments passed to your program, you have to use the special expression `"$@"`: `for f in "$@"`. – user1934428 Aug 17 '20 at 09:58

0 Answers0