28 lines
501 B
Bash
Executable File
28 lines
501 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail
|
|
|
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
|
cat <<EOF
|
|
Usage: $(basename "$0") [-h] <lineno> <file>
|
|
|
|
Display a specific line from a file.
|
|
|
|
Options:
|
|
-h, --help Show this help message
|
|
|
|
Arguments:
|
|
lineno Line number to display (1-based)
|
|
file File to read from
|
|
|
|
EOF
|
|
exit 0
|
|
fi
|
|
|
|
lineno="$1"; shift
|
|
|
|
if [[ ! -t 0 ]]; then # Read from stdin (pipe)
|
|
sed -n "${lineno}p"
|
|
else # Read from file
|
|
sed -n "${lineno}p" -- "$@"
|
|
fi
|