3

Suppose I have a bash for-loop

for name in *; do
    printf $(some stats about $name)
done

Now I would like to also print the same stats about the current folder itself, in other word, something like

for name in (* and .); do   # NOT VALID BASH COMMAND
    printf $(some stats about $name)
done

My question is what should I do for the "pseudo-command" (* and .)?

I know I can simply do printf $(some stats about .) after the for-loop, but I would like to know whether there is a more generic way of doing so. (Just assume $(some stats about $name) is long and I would like to avoid defining another function if possible). Thanks!

1 Answer 1

3

Try simply

for name in * . ; do
    printf $(some stats about $name)
done

to add an element to the list over which the for loop runs.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, didn't expect something so simple.. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.