add proper error handling for all final exec calls
[hband-tools.git] / user-tools / tests
blob54da274c5ac3cd9fd483bb84b910e595581d3762
1 #!/bin/bash
3 true <<EOF
4 =pod
6 =head1 NAME
8 tests - Show all attributes of the given files which can be tested by test(1) in the same color as ls(1) shows them
10 =cut
12 EOF
15 color=yes
16 filenames=yes
17 sem=":"
19 while [ -n "$1" ]; do
20 case "$1" in
21 -h|--help)
22 echo "${0##*/} [-nc] [-s mark] [-F] <files>
23 Displays files /directories/ details reported by test(1)
24 -nc no color
25 -s CHAR put CHAR after filenames, instead of semicolon
26 -F don't output filenames"
27 exit 0
29 -nc) color=no
31 -s) shift
32 sem="$1"
34 -F) filenames=no
36 -*) shift;;
37 *) break;;
38 esac
39 shift
40 done
42 if [ $color = yes ]; then
43 # default colors
44 NO="\e[00m"
45 RF="\e[00m"
46 DIR="\e[01;34m"
47 SL="\e[01;36m"
48 PI="\e[40;33m"
49 SO="\e[40;33m"
50 DO="\e[40;33m"
51 BS="\e[44;33;01m"
52 CS="\e[44;33;01m"
53 NONE="\e[40;31;01m"
54 UNREAD="\e[40;31;01m"
55 SUID="\e[01;41m"
56 SGID="\e[30;41m"
57 STICKY="\e[35;40m"
58 X="\e[01;32m"
59 W="\e[00;42m"
61 # determine colors bases on LS_COLORS
62 oldifs="$IFS"
63 IFS=":"
64 for typecolor in $LS_COLORS; do
65 type=${typecolor/=*}
66 color="\e[${typecolor/*=}m"
67 case $type in
68 no) NO="$color";;
69 fi) RF="$color";;
70 di) DIR="$color";;
71 ln) SL="$color";;
72 pi) PI="$color";;
73 so) SO="$color";;
74 do) DO="$color";;
75 bd) BS="$color";;
76 cd) CS="$color";;
77 mi) NONE="$color";;
78 or) UNREAD="$color";;
79 su) SUID="$color";;
80 sg) SGID="$color";;
81 st) STICKY="$color";;
82 ex) X="$color";;
83 ow) W="$color";;
84 esac
85 done
86 IFS="$oldifs"
87 else # no color
88 NO=''
89 RF=''
90 DIR=''
91 SL=''
92 PI=''
93 SO=''
94 DO=''
95 BS=''
96 CS=''
97 NONE=''
98 UNREAD=''
99 SUID=''
100 SGID=''
101 STICKY=''
102 X=''
103 W=''
106 #for line in `cat`; do
107 for line in "$@"; do
108 bs=''
109 cs=''
110 d=''
111 l=''
112 rf=''
113 sgid=''
114 suid=''
115 g=''
116 o=''
117 st=''
118 gtz=''
119 r=''
120 w=''
121 x=''
122 so=''
123 pi=''
125 if [ -e "$line" ]; then
126 [ -b "$line" ] && bs=y
127 [ -c "$line" ] && cs=y
128 [ -d "$line" ] && d=y
129 [ -L "$line" ] && l=y
130 [ -f "$line" ] && rf=y
131 [ -g "$line" ] && sgid=y
132 [ -u "$line" ] && suid=y
133 [ -G "$line" ] && g=y
134 [ -O "$line" ] && o=y
135 [ -k "$line" ] && st=y
136 [ -s "$line" ] && gtz=y
137 [ -r "$line" ] && r=y
138 [ -w "$line" ] && w=y
139 [ -x "$line" ] && x=y
140 [ -S "$line" ] && so=y
141 [ -p "$line" ] && pi=y
143 if [ -n "$r" -a -z "$w" ]; then
144 res="${RF}R/O${NO}"
145 elif [ -n "$r" -a -n "$w" ]; then
146 res="${W}R/W${NO}"
147 else
148 res="${UNREAD}unreadable${NO}"
150 if [ -n "$rf" -a -z "$gtz" ]; then res="$res ${NO}empty${NO}"; fi
151 if [ -n "$x" -a -z "$d" ]; then res="$res ${X}executable${NO}";
152 elif [ -n "$x" ]; then res="$res ${X}browsable${NO}"; fi
153 [ -n "$bs" ] && res="$res ${BS}block_special${NO}"
154 [ -n "$cs" ] && res="$res ${CS}character_special${NO}"
155 [ -n "$so" ] && res="$res ${SO}socket${NO}"
156 [ -n "$pi" ] && res="$res ${PI}named_pipe${NO}"
157 [ -n "$d" ] && res="$res ${DIR}directory${NO}"
158 [ -n "$l" ] && res="$res ${SL}symbolic_link${NO}"
159 [ -n "$rf" ] && res="$res ${RF}regular_file${NO}"
160 [ -n "$sgid" ] && res="$res ${SGID}set_group_ID${NO}"
161 [ -n "$suid" ] && res="$res ${SUID}set_user_ID${NO}"
162 [ -n "$g" ] && res="$res ${NO}owned_by_EGID${NO}" # ${SGID}
163 [ -n "$u" ] && res="$res ${SUID}owned_by_EUID${NO}"
164 [ -n "$st" ] && res="$res ${STICKY}set_sticky_bit${NO}"
165 else
166 res="${NONE}nonexistent${NO}"
169 if [ $filenames = yes ]; then
170 res="${NO}${line}${sem} $res${NO}"
172 echo "$res"
173 done