Unix/ls: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(2 intermediate revisions by one other user not shown)
Line 1,840:
 
=={{header|UNIX Shell}}==
 
ls sorts by default, if it doesn't work for you, pipe it's output to sort :
Using `ls` explicitly would be a cheat, since the goal of the task is to emulate this program.
<syntaxhighlight lang="bash">
 
Aamrun $ ls -1
A simple way to list files in the current directory without using `ls` is to
Applications
use filename expansion (a.k.a. "globbing").
Desktop
 
Documents
<syntaxhighlight lang="bash">echo *</syntaxhighlight>
Downloads
 
KeyGenerator.png
To print each filename on a separate line, use a loop:
Library
 
Movies
<syntaxhighlight lang="bash">for f in *; do echo "$f"; done</syntaxhighlight>
Music
 
My Projects
If you want this output sorted, then use `sort`:
Pictures
 
Public
<syntaxhighlight lang="bash">for f in *; do echo "$f"; done |sort</syntaxhighlight>
Aamrun $ ls -1|sort
 
Applications
An other possibility is to use GNU coreutils' `stat`:
Desktop
 
Documents
<syntaxhighlight lang="bash">stat -c %n * |sort</syntaxhighlight>
Downloads
 
KeyGenerator.png
Library
Movies
Music
My Projects
Pictures
Public
Aamrun $
</syntaxhighlight>
=={{header|Ursa}}==
<syntaxhighlight lang="ursa">decl file f
Line 1,886 ⟶ 1,878:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "io" for Directory
 
var path = "./" // or whatever
9,488

edits