Reputation: 61
I want to create a filename with declared $TENANT variable name.so when I am trying to create a file with variable declared it is taking $TENANT variable as file name but adding ? at the end of the file name
Expected output: $TENANT=cat123dbg
File should be created with $TENANT
variable i.e cat123dbg.txt
or any extension.but the file is created with cat123dbg?($tenant variable name with ?)
can someone please help me..
print "Enter the tenant name:"
$TENANT=gets.chomp('/\p{Alnum}/')
$first = $TENANT.slice(0,1).capitalize
$second =$TENANT.slice(1..-1)
$PASSWORD="Export-"+ $first + $second.chomp + "!"
FILENAME=$TENANT.chomp + ".xar"
file = File.open("../input/exporttenant.rb", "r")
$line = file.readlines.select{|line| line.match('DS_ENTRY_OMS_SERVER')}
file.close
output=File.open("../input/#{$TENANT}", 'w')
output.puts "TENANT_NAME=#{$TENANT}"
output.puts "EXPORT_PASSWORD=#{$PASSWORD}"
output.puts "EXPORT_FILENAME=#{FILENAME}"
output.puts "EXPORT_WITHOUT_TAR=N"
output.puts "BYPASS_BLOB=N"
output.puts $line
output.close
print "Export tenant created for the #{$TENANT}\n"
Upvotes: 0
Views: 2313
Reputation: 36860
Use string interpolation to replace "$TENANT" with the contents of the variable $TENANT
.
Instead of...
output=File.open("/../Desktop/input/$TENANT", 'w')
Do...
output=File.open("/../Desktop/input/#{$TENANT}", 'w')
Upvotes: 4