Thanks again Susan. I agree that this is truly a shell scripting question. I placed it here because I was hoping that someone (like yourself :) ) would have easy examples of other things they've done in the psql space. I actually did want to insert a litteral version of the variable. I found my problem by indirectly noticing somethign in your example. My code wasn't working because of a "Space" character between the "=" and "psql". I'm not an expert in shell scripting and I wasn't aware that a space would actually make a difference.. example... ## Code SERVERCOLLECTIONTIMEID = `psql Admin -Upostgres -hMYSERVER -t -c"INSERT INTO servercollectiontime(batchtime) VALUES('$BATCHTIME'); SELECT currval('servercollectiontime_servercollectiontimeid_seq');"` echo "SERVERCOLLECTIONTIMEID is: $SERVERCOLLECTIONTIMEID" ## RETURN SERVERCOLLECTIONTIMEID is: (you'll notice that there is just whitespace after the is) If I change the code to remove the space around the "=" SERVERCOLLECTIONTIMEID=`psql ... I get this... SERVERCOLLECTIONTIMEID is: 11 now that the variable is set correctly, it works in my insert statement further in the code... I actually did want to insert the literal value of the variable because that will end up being a foreign key to this table... Thanks for all the help susan. I will update my blog to include this newest version.. Also, thanks for the multiple examples in your last post. Those are definitely going to come in handy for some of my other development... -Paul Paul Silveira wrote: > > Hello, > > I would like to create a shell script that would populate two variables > with the return of a SELECT statement that would return two attributes... > > For example... > > #!/bin/bash > SERVER_NAMES=`psql Admin -Upostgres -hMYSERVER -t -c"SELECT servername, > instanceport from server where serverclass = 3 and isactive = 'True' ";` > > > As you can see, I'm returning the servername "and" the instanceport from > the server table. This will later allow me to create psql commands to > connect to each server dynamically. > > I had the script working correctly when I was just running it for the > server name as below... > #!/bin/bash > SERVER_NAMES=`psql Admin -Upostgres -hMYSERVER -t -c"SELECT servername > from server where serverclass = 3 and isactive = 'True' ";` > > > Does anyone know the easiest way to get both values out of some variables > that I could set? > > Later in the script, I'm creating a for loop and iterating through the > server names and would like to build connection strings dynamically with > the results from the select string... > > > > for i in $SERVER_NAMES > do > psql -Upostgres -h$i -p$i -A -t -c"SELECT '$i', '$BATCHTIME', name, > setting, category, short_desc, context, vartype, source, min_val, max_val > FROM pg_settings;" | psql Admin -Upostgres -hMYSERVER -t -c"COPY > serverconfigsetting FROM STDIN WITH DELIMITER '|' NULL AS '';" > echo "Done with $i" > done > > > As you can see I have "-h$i -p$i" in the script for the host and port. > Again the script worked fine when I just had the -h@i in there... > > I know that the current forloop is incorrect specifiying the $i twice but > I just put that in there to show an example of what I was hoping to do... > It would probably be more accessing the array value like -h$i[0:0] > -p$i[0:1] in pseudo code for accessing array values. > > Thanks in advance, > > Paul > > > > > > -- View this message in context: http://www.nabble.com/shell-script-to-populate-array-values-tf2796502.html#a7880857 Sent from the PostgreSQL - general mailing list archive at Nabble.com.