Home > Enterprise >  I have a problem trying to put single quotes around a text
I have a problem trying to put single quotes around a text

Time:02-17

I have a password that has special character with an exclamation point.

ABcD!987zyz12388

I'd like to put single quotes around it. This password is fetched and saved to a variable.

$mypass=`fetchpwd $sourceserver $loginacct`;
$mypass="'$mypass'";

print "My password is: $mypass\n";

The return looks like this

My Password is 'ABcD!987zyz12388
'

The end single quote went on the next line. How can I have the last single quote right after the last 8 to something like this 'ABcD!987zyz12388'

CodePudding user response:

Use chomp to remove the newline character which is added by your fetchpwd command. Do this before you add single quotes.

$mypass=`fetchpwd $sourceserver $loginacct`;
chomp $mypass;
$mypass="'$mypass'";

print "My password is: $mypass\n";
  •  Tags:  
  • perl
  • Related