|
Home > Archive > Unix Shell > August 2006 > How to make a bourne shell user-defined function take input from heredoc
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to make a bourne shell user-defined function take input from heredoc
|
|
| Rakesh Sharma 2006-08-25, 7:33 am |
| hi,
how do we make a user-defined function in bourne shells to be able to
take it's input(s) from either it's argument list or a heredoc?
For example,
func1() {
printf '%s\n' "$@"
return 0
}
func1 "$var1" 'arg2' # works fine when arguments provided
# by means of shell variables or hardcoded strings
# but this doesnt work
func1 << EOF
this is some heredoc
usage: FOOBAR tmpdir tmpfile codename
EOF
Regards,
Rakesh
| |
| Stephane Chazelas 2006-08-25, 7:33 am |
| On 25 Aug 2006 03:40:49 -0700, Rakesh Sharma wrote:
> hi,
>
> how do we make a user-defined function in bourne shells to be able to
> take it's input(s) from either it's argument list or a heredoc?
>
> For example,
>
> func1() {
> printf '%s\n' "$@"
> return 0
> }
>
> func1 "$var1" 'arg2' # works fine when arguments provided
> # by means of shell variables or hardcoded strings
>
> # but this doesnt work
> func1 << EOF
> this is some heredoc
> usage: FOOBAR tmpdir tmpfile codename
> EOF
[...]
func1() {
if [ "$#" -eq 0 ]; then
cat
else
printf '%s\n' "$@"
fi
return 0
}
--
Stephane
|
|
|
|
|