-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessStdinWithArgs.sh
More file actions
executable file
·106 lines (88 loc) · 2.85 KB
/
processStdinWithArgs.sh
File metadata and controls
executable file
·106 lines (88 loc) · 2.85 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
IcmBriefDescription="A minimal but complete example for a bash command capable of accepting inputs from stdin and applying args."
ORIGIN="
* Libre-Halaal CopyLeft -- Part Of ByStar -- Best Used With Blee
"
####+BEGINNOT: bx:bash:top-of-file :vc "cvs" partof: "bystar" :copyleft "halaal+brief"
####+END:
__author__="
* Authors: Mohsen BANAN, http://mohsen.banan.1.byname.net/contact
"
####+BEGINNOT: bx:bsip:bash:seed-spec :types "seedActions.bash"
SEED="
* /[dblock]/ /Seed/ :: [[file:/bisos/core/bsip/bin/seedActions.bash]] |
"
FILE="
* /This File/ :: /bisos/git/bxRepos/bxexamples/bashProcessArgsAndStdin/processArgsAndStdin.sh
"
if [ "${loadFiles}" == "" ] ; then
/usr/local/bin/seedIcmStandalone.bash -l $0 "$@"
exit $?
fi
####+END:
function vis_examples {
local extraInfo="-h -v -n showRun"
visLibExamplesOutput ${G_myName}
cat << _EOF_
$( examplesSeperatorTopLabel "${G_myName}" )
$( examplesSeperatorChapter "Cmnd Line Args" )
${G_myName} -i processInputs arg1 "arg2 including spaces"
${G_myName} ${extraInfo} -i processInputs arg1 "arg2 including spaces"
$( examplesSeperatorChapter "Stdin Input" )
printf "stdin1 with spaces\nstdin2\n" | ${G_myName} -i processInputs
printf "stdin1 with spaces\nstdin2\n" | ${G_myName} ${extraInfo} -i processInputs
$( examplesSeperatorChapter "Stdin Input And Cmnd Line Args" )
printf "stdin1 with spaces\nstdin2\n" | ${G_myName} -i processInputs arg1 "arg2 including spaces"
printf "stdin1 with spaces\nstdin2\n" | ${G_myName} ${extraInfo} -i processInputs arg1 "arg2 including spaces"
_EOF_
}
function noArgsHook {
vis_examples
}
function vis_processInputs {
G_funcEntry
function describeF { G_funcEntryShow; cat << _EOF_
Function description.
Design Pattern: processEach stdin with args.
Examples:
${G_myName} -i ${G_thisFunc} someArg1 someArg2
printf "someStdin1\nsomeStdin2\n" | ${G_myName} -i ${G_thisFunc} someArg1 someArg2
_EOF_
}
local thisFunc=${G_thisFunc}
function processEach {
EH_assert [[ $# -gt 0 ]]
local each="$1"
shift
lpDo echo "Processing ${thisFunc}:: ${each} $@"
lpReturn 0
}
####+BEGIN: bx:bsip:bash/processStdinWithArgs
function processStdinWithArgs {
local stdinArgs
local each
if [ ! -t 0 ]; then # FD 0 is not opened on a terminal, there is a pipe
readarray stdinArgs < /dev/stdin
fi
if [ ${#stdinArgs[@]} -eq 0 ] ; then
ANT_raw "No StdinArgs -- Processing Skipped"
lpReturn
fi
for each in "${stdinArgs[@]}"; do
lpDo processEach "${each%$'\n'}" "$@"
done
}
lpDo processStdinWithArgs "$@"
####+END:
lpReturn
}
####+BEGIN: bx:dblock:bash:end-of-file :type "basic"
_CommentBegin_
* [[elisp:(org-cycle)][| ]] Common :: /[dblock] -- End-Of-File Controls/ [[elisp:(org-cycle)][| ]]
_CommentEnd_
#+STARTUP: showall
#local variables:
#major-mode: sh-mode
#fill-column: 90
# end:
####+END: