0

I am trying to build a script from the command line. But everytime I run, my echo command only prints the directory name and not the files inside the directory.

for EachFile in $1:
do
  #Do stuff
  echo "Filename is $EachFile"

done
1
  • for var in ... iterates over the list of "words" following in, not over files in a directory. To iterate over the files in a directory, you need to convert the list of files in that directory into a list of words, and a shell wildcard expression (like "$dir"/*) is the best way to do that. Commented Mar 18, 2021 at 20:29

1 Answer 1

1

Colon has no special meaning in paths. Use a glob:

for file in "$1"/* ; do
    printf '%s\n' "$file"
done
Sign up to request clarification or add additional context in comments.

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.