Operating System - HP-UX
1849272 Members
6501 Online
104042 Solutions
New Discussion

Re: How can i show a variable value given in a string?

 
SOLVED
Go to solution
Manuales
Super Advisor

How can i show a variable value given in a string?

Hi ..
i'm using a function wich obtains a line with information to create a file which will be used by ftp command as follows:


main script has configured the following line:
interface_name=/home/user1
functons_path=/home/user1/FUNCTIONS
fpgp2=new_file.txt

fun_sendinf_ftp $interface_name $functions_path $interface_log $fpgp2
DATOS=user=open#111.222.333.444=user#test#test=binary=prompt#off=mput#$fpgp2=dir#$fpgp2=bye


#---> This is function file:
function fun_sendinf_ftp
{
for a in `echo $DATOS | sed 's/=/ /g'`
do
if [[ $x > 1 ]]
then
echo $a | sed 's/#/ /g' >> $logftp
fi
let "x = x + 1"
done
}

the $logftp file contains:
open 111.222.333.444
user test test
binary
prompt off
mput $fpgp2
dir $fpgp2
bye

My doubt here is:
how must i do to see the value of $fpgp2 into $logftp file?
I'm running:
echo $a | sed 's/#/ /g' >> $logftp

i thought that with echo command would show the value of the variable $fpgp2 but NOT !!!
it appears as string but that is a value and that value is given when is invoking the function:
fun_sendinf_ftp $interface_name $functions_path $interface_log $fpgp2

How can i see the value?
I think it must run an exec command or something like that

please help!!!

Thanks !!
Manuales.
4 REPLIES 4
Warren_9
Honored Contributor
Solution

Re: How can i show a variable value given in a string?

Hi Manuales,

what shell r u using??

I have a test on your script, it work!!

#!/bin/sh
fpgp2=hehe

DATOS="open#111.222.333.444=user#test#test=binary=prompt#off=mput#$fpgp2=dir#$fpgp2=bye"

function fun_sendinf_ftp
{
x=1
for a in `echo $1 | sed 's/=/ /g'`
do
if [[ $x > 0 ]]
then
echo $a | sed 's/#/ /g'
fi
let "x = x + 1"
done
}

fun_sendinf_ftp $DATOS

OUTPUT:
open 111.222.333.444
user test test
binary
prompt off
mput hehe
dir hehe
bye

GOOD LUCK!!
Manuales
Super Advisor

Re: How can i show a variable value given in a string?

I'm using ksh ....
DO NOT WORK!!!

:'(
Warren_9
Honored Contributor

Re: How can i show a variable value given in a string?

hi,

did you try to put a " " on the DATOS= ??
and using ${fpgp2} to call the variable?

BTW, the script also work in ksh.

GOOD LUCK!
Peter Nikitka
Honored Contributor

Re: How can i show a variable value given in a string?

Hi,

I can't see, where youre variable x is preset,
try
function fun_sendinf_ftp
{
typeset -i x=0
for a in ...
...
((x+=1))
done
}

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"