Korn Shell help - Using parameter to create variable names

I'm using korn shell and I am wondering if it's possible to use a parameter passed into a function to build a variable name in a configuration file. I have the function in one source file, I'd like to have a global configuration file instead of hardcoding logins to each script.

So I have a function, it accepts a system ID and I want to use that ID to read a configuration file for the server, user name and login for several different FTP sites. When I pass in the system ID of boe I then want to read the configuration file for boeServer, boeUser and boePassword but keep getting not found.

This is my source file functions:

function ftpConfirm {
system=$1
# Configuration file to look up FTP information
. $HOME/ftpLogins
server="${system}Server"
user="${system}User"
password="${system}Password"
echo "**** System variable passed in: $system"
echo "**** Server we are connecting to: $server"
echo "**** User name: $user"
echo "**** Password: $password"
echo "* Just referencing the variable returns the results I want: $boeServer"

Here's my config file ftpLogins:

export boeServer=ftp1
export boeUser=teamUser
export boePassword=download
export ibmServer=ibm1
export ibmUser=teamUser
export ibmPassword=download

And a simple script to call the function that I'm using:

#!/bin/ksh -f
. $HOME/fucntions
ftpConfirm "boe"

This would allow us to essentially build one function that could FTP anywhere we need and if we FTP to that server more than once, we would have to make just one change.

Thanks in advance,
Mike

You must reevaluate using eval, like to print the last argument:

eval echo '$'$#

That worked on the echo commands only. Now when I'm using the eval during the FTP, it's not reading the user name and password. I keep getting the error: 530 Please login with USER and PASS.

eval ftp -n -v '$'$server <<++EOF++ > logfile
eval user '$'$user '$'$password

Seems like it's connecting to the server, I see some messages. But it's not recognizing the user name or password variables.

Thanks,
Mike

If someone puts `rm -Rf /home/username` into your config file, eval will execute that!

Fortunately you don't need eval to set arbitrary variables, read can do that.

A=abc
B=def

read ${A}${B} <<EOF
string
EOF

echo "abcdef = ${abcdef}"

Neat! I suppose that might work in some other places where variables have no $, if any.

I was able to get the eval to work but no luck on the read. I'm curious because I don't want someone accidentally running a command. However, after a few hours of trying different combinations, read wouldn't resolve a string. Take the following sample, the script would just hang.

read ${server} <<EOF
${system}Server
EOF

Per my samples where I pass in boe, I figured it would've resolved the ${system} to be boe and then look up boeServer in the ftpLogins file. In the end, I expect the variable server to have the value ftp1. While I'm happy for the eval solution, security wise I'd love to use read if I could.

Thanks,
Mike

Not sure what your read was supposed to do. The read example worked for you, didn't it?

Eval is like 'echo ... | ksh' but cheaper without the fork, exec, pipe, nice in high rep loops.

That's exactly backwards. Remember, read varnablename . You're trying to put the data there.

read ${system}Server <<EOF
${server}
EOF