bash: how for loop sorts files when iterating [duplicate]

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
This question already has an answer here:
Does the Bash star * wildcard always produce an (ascending) sorted list?
4 answers
What is the default behavior of for loop in terms of sorting when listing files in a directory?
e.g.
for sqlfile in *.sql; do mysql -u root -p pass < sqlfile; done
Is this documented somewhere?
bash sort for
marked as duplicate by Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
May 30 at 9:49
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
0
down vote
favorite
This question already has an answer here:
Does the Bash star * wildcard always produce an (ascending) sorted list?
4 answers
What is the default behavior of for loop in terms of sorting when listing files in a directory?
e.g.
for sqlfile in *.sql; do mysql -u root -p pass < sqlfile; done
Is this documented somewhere?
bash sort for
marked as duplicate by Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
May 30 at 9:49
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
It does not sort ever. It is the glob (*.sql) that is doing the sorting.
â ctrl-alt-delor
May 30 at 9:41
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This question already has an answer here:
Does the Bash star * wildcard always produce an (ascending) sorted list?
4 answers
What is the default behavior of for loop in terms of sorting when listing files in a directory?
e.g.
for sqlfile in *.sql; do mysql -u root -p pass < sqlfile; done
Is this documented somewhere?
bash sort for
This question already has an answer here:
Does the Bash star * wildcard always produce an (ascending) sorted list?
4 answers
What is the default behavior of for loop in terms of sorting when listing files in a directory?
e.g.
for sqlfile in *.sql; do mysql -u root -p pass < sqlfile; done
Is this documented somewhere?
This question already has an answer here:
Does the Bash star * wildcard always produce an (ascending) sorted list?
4 answers
bash sort for
asked May 30 at 9:36
pkaramol
240112
240112
marked as duplicate by Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
May 30 at 9:49
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
May 30 at 9:49
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
It does not sort ever. It is the glob (*.sql) that is doing the sorting.
â ctrl-alt-delor
May 30 at 9:41
add a comment |Â
2
It does not sort ever. It is the glob (*.sql) that is doing the sorting.
â ctrl-alt-delor
May 30 at 9:41
2
2
It does not sort ever. It is the glob (
*.sql) that is doing the sorting.â ctrl-alt-delor
May 30 at 9:41
It does not sort ever. It is the glob (
*.sql) that is doing the sorting.â ctrl-alt-delor
May 30 at 9:41
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
According to man bash's section on "Pathname Expansion":
If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern [â¦]
This sorting depends on the value of $LC_COLLATE:
This variable determines the collation order used when sorting the results of pathname expansion [â¦]
As you can see from the above, this has nothing to do with the for loop. Globs can be used in many ways, and their expansion is always sorted.
2
fordoes not sort ever. It is the glob (*.sql) that is doing the sorting.
â ctrl-alt-delor
May 30 at 9:42
Sure, I'm just explaining how the sorting that happens in theforloop works.
â l0b0
May 30 at 9:43
1
For me to accept the answer, the comment of ctrl-alt-delor on the glob should be added.
â pkaramol
May 30 at 9:44
+1 for the LC_COLLATE observation.
â Rui F Ribeiro
May 30 at 9:47
add a comment |Â
up vote
2
down vote
for loops don't sort, they give you the values in exactly the order they were presented:
$ for x in b a c ; do echo $x ; done
b
a
c
Globs, on the other hand, do sort alphabetically, regardless of if you use them in a for or anywhere else:
$ touch b a c
$ echo *
a b c
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
According to man bash's section on "Pathname Expansion":
If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern [â¦]
This sorting depends on the value of $LC_COLLATE:
This variable determines the collation order used when sorting the results of pathname expansion [â¦]
As you can see from the above, this has nothing to do with the for loop. Globs can be used in many ways, and their expansion is always sorted.
2
fordoes not sort ever. It is the glob (*.sql) that is doing the sorting.
â ctrl-alt-delor
May 30 at 9:42
Sure, I'm just explaining how the sorting that happens in theforloop works.
â l0b0
May 30 at 9:43
1
For me to accept the answer, the comment of ctrl-alt-delor on the glob should be added.
â pkaramol
May 30 at 9:44
+1 for the LC_COLLATE observation.
â Rui F Ribeiro
May 30 at 9:47
add a comment |Â
up vote
3
down vote
According to man bash's section on "Pathname Expansion":
If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern [â¦]
This sorting depends on the value of $LC_COLLATE:
This variable determines the collation order used when sorting the results of pathname expansion [â¦]
As you can see from the above, this has nothing to do with the for loop. Globs can be used in many ways, and their expansion is always sorted.
2
fordoes not sort ever. It is the glob (*.sql) that is doing the sorting.
â ctrl-alt-delor
May 30 at 9:42
Sure, I'm just explaining how the sorting that happens in theforloop works.
â l0b0
May 30 at 9:43
1
For me to accept the answer, the comment of ctrl-alt-delor on the glob should be added.
â pkaramol
May 30 at 9:44
+1 for the LC_COLLATE observation.
â Rui F Ribeiro
May 30 at 9:47
add a comment |Â
up vote
3
down vote
up vote
3
down vote
According to man bash's section on "Pathname Expansion":
If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern [â¦]
This sorting depends on the value of $LC_COLLATE:
This variable determines the collation order used when sorting the results of pathname expansion [â¦]
As you can see from the above, this has nothing to do with the for loop. Globs can be used in many ways, and their expansion is always sorted.
According to man bash's section on "Pathname Expansion":
If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern [â¦]
This sorting depends on the value of $LC_COLLATE:
This variable determines the collation order used when sorting the results of pathname expansion [â¦]
As you can see from the above, this has nothing to do with the for loop. Globs can be used in many ways, and their expansion is always sorted.
edited May 30 at 20:46
answered May 30 at 9:40
l0b0
26k17104226
26k17104226
2
fordoes not sort ever. It is the glob (*.sql) that is doing the sorting.
â ctrl-alt-delor
May 30 at 9:42
Sure, I'm just explaining how the sorting that happens in theforloop works.
â l0b0
May 30 at 9:43
1
For me to accept the answer, the comment of ctrl-alt-delor on the glob should be added.
â pkaramol
May 30 at 9:44
+1 for the LC_COLLATE observation.
â Rui F Ribeiro
May 30 at 9:47
add a comment |Â
2
fordoes not sort ever. It is the glob (*.sql) that is doing the sorting.
â ctrl-alt-delor
May 30 at 9:42
Sure, I'm just explaining how the sorting that happens in theforloop works.
â l0b0
May 30 at 9:43
1
For me to accept the answer, the comment of ctrl-alt-delor on the glob should be added.
â pkaramol
May 30 at 9:44
+1 for the LC_COLLATE observation.
â Rui F Ribeiro
May 30 at 9:47
2
2
for does not sort ever. It is the glob (*.sql) that is doing the sorting.â ctrl-alt-delor
May 30 at 9:42
for does not sort ever. It is the glob (*.sql) that is doing the sorting.â ctrl-alt-delor
May 30 at 9:42
Sure, I'm just explaining how the sorting that happens in the
for loop works.â l0b0
May 30 at 9:43
Sure, I'm just explaining how the sorting that happens in the
for loop works.â l0b0
May 30 at 9:43
1
1
For me to accept the answer, the comment of ctrl-alt-delor on the glob should be added.
â pkaramol
May 30 at 9:44
For me to accept the answer, the comment of ctrl-alt-delor on the glob should be added.
â pkaramol
May 30 at 9:44
+1 for the LC_COLLATE observation.
â Rui F Ribeiro
May 30 at 9:47
+1 for the LC_COLLATE observation.
â Rui F Ribeiro
May 30 at 9:47
add a comment |Â
up vote
2
down vote
for loops don't sort, they give you the values in exactly the order they were presented:
$ for x in b a c ; do echo $x ; done
b
a
c
Globs, on the other hand, do sort alphabetically, regardless of if you use them in a for or anywhere else:
$ touch b a c
$ echo *
a b c
add a comment |Â
up vote
2
down vote
for loops don't sort, they give you the values in exactly the order they were presented:
$ for x in b a c ; do echo $x ; done
b
a
c
Globs, on the other hand, do sort alphabetically, regardless of if you use them in a for or anywhere else:
$ touch b a c
$ echo *
a b c
add a comment |Â
up vote
2
down vote
up vote
2
down vote
for loops don't sort, they give you the values in exactly the order they were presented:
$ for x in b a c ; do echo $x ; done
b
a
c
Globs, on the other hand, do sort alphabetically, regardless of if you use them in a for or anywhere else:
$ touch b a c
$ echo *
a b c
for loops don't sort, they give you the values in exactly the order they were presented:
$ for x in b a c ; do echo $x ; done
b
a
c
Globs, on the other hand, do sort alphabetically, regardless of if you use them in a for or anywhere else:
$ touch b a c
$ echo *
a b c
answered May 30 at 9:45
ilkkachu
47.8k668131
47.8k668131
add a comment |Â
add a comment |Â
2
It does not sort ever. It is the glob (
*.sql) that is doing the sorting.â ctrl-alt-delor
May 30 at 9:41