NBash
46 строк · 814.0 Байт
1#!/bin/bash
2
3function usage {
4cat << EOF >&2
5Usage: $0 [DOS flags] directory or directories
6Where:
7/D sort by columns
8/H show help
9/N show long listing format with filenames on right
10/OD sort by oldest to newest
11/O-D sort by newest to oldest
12/P pause after each screenful of information
13/Q show owner of the file
14/S recursive listing
15/W use wide listing format
16EOF
17exit 1
18}
19
20# Основной сценарий
21
22postcmd=""
23flags=""
24
25while [ $# -gt 0 ]
26do
27case $1 in
28/D ) flags="$flags -x" ;;
29/H ) usage ;;
30/[NQW] ) flags="$flags -l" ;;
31/OD ) flags="$flags -rt" ;;
32/O-D ) flags="$flags -t" ;;
33/P ) postcmd="more" ;;
34/S ) flags="$flags -s" ;;
35* ) break ;;
36esac
37shift
38done
39
40if [ ! -z "$postcmd" ] ; then
41ls $flags "$@" | $postcmd
42else
43ls $flags "$@"
44fi
45
46exit 0