Unix/ls: Difference between revisions
→{{header|UNIX Shell}}: not using ls
(→{{header|UNIX Shell}}: not using ls) |
|||
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>
Finally, if you want this output sorted, then use `sort`:
<syntaxhighlight lang="bash">for f in *; do echo "$f"; done |sort</syntaxhighlight>
=={{header|Ursa}}==
<syntaxhighlight lang="ursa">decl file f
|