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}}==
Using `ls` explicitly would be a cheat, since the goal of the task is to emulate this program.
<syntaxhighlight lang="bash">▼
A simple way to list files in the current directory without using `ls` is to
use filename expansion (a.k.a. "globbing").
▲<syntaxhighlight lang="bash">echo *</syntaxhighlight>
To print each filename on a separate line, use a loop:
<syntaxhighlight lang="bash">for f in *; do echo "$f"; done</syntaxhighlight>
If you want this output sorted, then use `sort`:
<syntaxhighlight lang="bash">for f in *; do echo "$f"; done |sort</syntaxhighlight>
An other possibility is to use GNU coreutils' `stat`:
<syntaxhighlight lang="bash">stat -c %n * |sort</syntaxhighlight>
=={{header|Ursa}}==
<syntaxhighlight lang="ursa">decl file f
Line 1,886 ⟶ 1,878:
=={{header|Wren}}==
<syntaxhighlight lang="
var path = "./" // or whatever
|