From: anju on
Hi All,

----------------------------
#!/usr/bin/ksh
echo_fun1() {

case $1 in
1)
echo "First : $2"
;;
2)
echo "Second"
;;
*)
echo "No echo Message"
;;
esac
}
------------------------------------
#!/usr/bin/ksh
.. echo_fun1
dd="variable passed"
echo_fun1 1 $dd
echo "done"

--------------------------------------------
#./test1
First : variable
done


Passing $dd to echo_fun1 is not printing the "passed" value.

why it's behaving like this and how to pass the entire string to called
function ?


Thanks,
an

From: Chris F.A. Johnson on
On 2006-03-30, anju wrote:
>
> ----------------------------
> #!/usr/bin/ksh
> echo_fun1() {
>
> case $1 in
> 1)
> echo "First : $2"
> ;;
> 2)
> echo "Second"
> ;;
> *)
> echo "No echo Message"
> ;;
> esac
> }
> ------------------------------------
> #!/usr/bin/ksh
> . echo_fun1
> dd="variable passed"
> echo_fun1 1 $dd
> echo "done"
>
> --------------------------------------------
> #./test1
> First : variable
> done
>
>
> Passing $dd to echo_fun1 is not printing the "passed" value.
>
> why it's behaving like this and how to pass the entire string to called
> function ?

I seem to recall that you have been told before to quote your
variables:

echo_fun1 1 "$dd"

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
From: Janis Papanagnou on
anju wrote:
> Hi All,
>
> ----------------------------
> #!/usr/bin/ksh
> echo_fun1() {
>
> case $1 in
> 1)
> echo "First : $2"
> ;;
> 2)
> echo "Second"
> ;;
> *)
> echo "No echo Message"
> ;;
> esac
> }
> ------------------------------------
> #!/usr/bin/ksh
> . echo_fun1
> dd="variable passed"
> echo_fun1 1 $dd

echo_fun1 1 "$dd"

> echo "done"
>
> --------------------------------------------
> #./test1
> First : variable
> done
>
>
> Passing $dd to echo_fun1 is not printing the "passed" value.
>
> why it's behaving like this and how to pass the entire string to called
> function ?

Because you forgot to quote the variable expansion, which is always
a Good Thing to do in the first place, as a rule of thumb.

Janis

> Thanks,
> an
>
From: anju on
> I seem to recall that you have been told before to quote your
>variables:

Sorry for my memory loss.

Thanks Johnson..