docs: describe the pmdaroot process interfaces
[pcp.git] / src / pmlogger / utilproc.sh
blob07be5d491e9dbde78ad57e9bd1bb089421a98410
1 # Helper procedures for the scripts usually run from cron, e.g.
2 # pmlogger_check, pmie_daily, etc
5 # Handle shell expansion and quoting for $dir and adjust $args as
6 # appropriate.
7 # Called with $dir and $args set from reading the control file.
8 # Returns $dir and $args which may be modified.
9 # May use _error().
11 _do_dir_and_args()
13 close_quote=''
14 do_shell=false
15 case "$dir"
17 \"*)
18 # "...."
19 close_quote='*"'
21 \`*)
22 # `....`
23 close_quote='*`'
25 *\`*)
26 _error "embedded \` without enclosing \": $dir"
28 \$\(*)
29 # $(....)
30 close_quote='*)'
32 *\$\(*)
33 _error "embedded \$( without enclosing \": $dir"
35 *\$*)
36 # ...$...
37 do_shell=true
39 esac
40 if [ -n "$close_quote" ]
41 then
42 # we have a "dir" argument that begins with one of the recognized
43 # quoting mechanisms ... append additional words to $dir (from
44 # $args) until quote is closed
46 newargs=''
47 newdir="$dir"
48 for word in $args
50 case $word
52 $close_quote)
53 newdir="$newdir $word"
54 do_shell=true
57 if $do_shell
58 then
59 # quote closed, gather remaining arguments
60 if [ -z "$newargs" ]
61 then
62 newargs="$word"
63 else
64 newargs="$newargs $word"
66 else
67 # still within quote
68 newdir="$newdir $word"
71 esac
72 done
73 if $do_shell
74 then
75 dir="$newdir"
76 args="$newargs"
77 else
78 _error "quote not terminated: $dir $args"
81 $do_shell && dir="`eval echo $dir`"