Grep exits with non-zero if it find no matches. But it doesn't matter in this case, so just carry on. Test: frameworks/base/tools/hiddenapi/sort_api.sh \ Test: frameworks/base/config/hiddenapi-light-greylist.txt Change-Id: I7c219ee617f7dfa3cff5232ab979cc4ba38ebbfd
25 lines
527 B
Bash
Executable File
25 lines
527 B
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
if [ -z "$1" ]; then
|
|
source_list=/dev/stdin
|
|
dest_list=/dev/stdout
|
|
else
|
|
source_list="$1"
|
|
dest_list="$1"
|
|
fi
|
|
# Load the file
|
|
readarray A < "$source_list"
|
|
# Sort
|
|
IFS=$'\n'
|
|
# Stash away comments
|
|
C=( $(grep -E '^#' <<< "${A[*]}" || :) )
|
|
A=( $(grep -v -E '^#' <<< "${A[*]}" || :) )
|
|
# Sort entries
|
|
A=( $(LC_COLLATE=C sort -f <<< "${A[*]}") )
|
|
A=( $(uniq <<< "${A[*]}") )
|
|
# Concatenate comments and entries
|
|
A=( ${C[*]} ${A[*]} )
|
|
unset IFS
|
|
# Dump array back into the file
|
|
printf '%s\n' "${A[@]}" > "$dest_list"
|