Reputation: 1198
What is the meaning of:
for i in *; do echo *; done
I am on Unix Terminal (Mac OS X)
Darwin localhost 13.1.0 Darwin Kernel Version 13.1.0: Thu Jan 16 19:40:37 PST 2014;
Upvotes: 0
Views: 88
Reputation: 453
many special symbol are used under unix shell,for about bash.
* represent all file name under current directory which split by space,you can use echo * for a test.
~ represent you home directory.
! used for history command.
# for the comment.
$ used for recognize variable
% used for jobs
^ used for history command,format as '^string1^string2^' to quick substitution.
& used for background job
* all file name under current directory which split by space.
() cooperate with $,$(command) equivalent with `command`,$((1 + 2)) calculate mathematic expression like expr command do.
- used for old pwd,you can use 'cd -' back to the directory you switch from.
= use for assignment.
you code
for i in *; do echo *; done
just a for loop print all file name under current directory.
Upvotes: 0
Reputation: 532538
It's a bit redundant. In both places, the *
will expand to every file in the current directory. So the loop will repeat once for every file, with i
set to a different file name each time. Then the body will simply output the name of every file, ignoring i
. So if you have 10 files in the directory, you'll print all 10 file names 10 times.
Upvotes: 1