-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert_file
More file actions
executable file
·39 lines (33 loc) · 812 Bytes
/
assert_file
File metadata and controls
executable file
·39 lines (33 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# by Stefan Ruedisuehli, 2015-08-25
DIRECTORY_CHECK=true
USAGE="Usage: $(basename ${0}) <FILE(S)>
Assert the existance of one or more files."
main()
{
# Eval inargs
local narg_min=1
[ ${#} -lt ${narg_min} ] && { echo "${USAGE}" >&2; return 1; }
# Check files
local stat=0
for file in "${@}"
do
if [ ! -f "${file}" ]
then
echo -n "error: file not found: '${file}'" >&2
if ${DIRECTORY_CHECK}
then
if [[ -d "${file}" ]]
then
echo -n " (is a directory)" >&2
else
echo -n " (is not a directory, either)" >&2
fi
fi
echo
stat=1
fi
done
return ${stat}
}
main "${@}"