Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with global variables

Status
Not open for further replies.

tmf33uk

Technical User
Aug 23, 2007
21
GB
Hi,

I am trying to concatenate the output of a while loop to a $message variable that will be printed once the loop has completed, but as it stands, it returns nothing from the inside $message variable.

I am currently not very interested in the else condition. As long as $inexistent has contained any value, I want $message to report on the list at the end. If none are listed, I will set a message to say that "Everything is hunky dory".

##################################################################
if [ ! -f ${oratab} ]
then
print "em_result=there is no oratab found in $oratab"
exit
else
awk -F":" '{ print $2 }' $oratab | while read line
do
if [ ! -f "${line}/network/admin/sqlnet.ora" ];
then
inexistent="${line}/network/admin"
route="${route} ${inexistent}, "
message="No sqlnet.ora file found in the following directories: ${route}."
else
existent=""${line}"/network/admin"
route2="${route2} ${existent}, "
message="An sqlnet.ora file was found in ${route2}"
exit
fi
done
print $message
fi
exit
#################################################################

Can anyone help with this?

Thanks in advance!

Regards,
T.
 
Hi

When you pipe into a compound command, it is executed as a child process.
Is impossible to set a process' environment from a child process.
Is impossible to access a process' environment after it terminates.

So instead of piping, set its input from somewhere else, like file, here document or here string :
Code:
[b]if[/b] [teal][[/teal] [teal]![/teal] -f [green][i]"${oratab}"[/i][/green] [teal]][/teal]
[b]then[/b]
  print [green][i]"em_result=there is no oratab found in $oratab"[/i][/green]
  [COLOR=chocolate]exit[/color]
[b]else[/b]
  [b]while[/b] [COLOR=chocolate]read[/color] line
  [b]do[/b]
    [b]if[/b] [teal][[/teal] [teal]![/teal] -f [green][i]"${line}/network/admin/sqlnet.ora"[/i][/green] [teal]][/teal]
    [b]then[/b]
      [navy]inexistent[/navy][teal]=[/teal][green][i]"${line}/network/admin"[/i][/green]
      [navy]route[/navy][teal]=[/teal][green][i]"${route} ${inexistent}, "[/i][/green]
      [navy]message[/navy][teal]=[/teal][green][i]"No sqlnet.ora file found in the following directories: ${route}."[/i][/green]
    [b]else[/b]
      [navy]existent[/navy][teal]=[/teal][green][i]"${line}/network/admin"[/i][/green]
      [navy]route2[/navy][teal]=[/teal][green][i]"${route2} ${existent}, "[/i][/green]
      [navy]message[/navy][teal]=[/teal][green][i]"An sqlnet.ora file was found in ${route2}"[/i][/green]
      [COLOR=chocolate]exit[/color]
    fi
  [b]done[/b] [highlight][teal]<<[/teal]ENDOFINPUT[/highlight]
[highlight][navy]$([/navy] awk -F[green][i]":"[/i][/green] [green][i]'{ print $2 }'[/i][/green] [navy]$oratab[/navy] [teal])[/teal][/highlight]
[highlight]ENDOFINPUT[/highlight]
  print [green][i]"$message"[/i][/green]
fi
[COLOR=chocolate]exit[/color]
[small][maroon]Warning[/maroon] The above code was not tested[/small]

Next time please post your code between [tt][ignore]
Code:
[/ignore][/tt] and [tt][ignore]
[/ignore][/tt] TGML tags.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top