Home > database >  How to put single quotes in bash
How to put single quotes in bash

Time:03-17

ABcD!987zyz12388

I'd like to put single quotes around it to handle special character/s. 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
'

CodePudding user response:

The quotes don't belong in the variable itself; they should be added by the printf statement that displays the value.

mypass=$(fetchpwd "$sourceserver" "$logginacct")
printf "My password is: '%s'\n" "$mypass"

CodePudding user response:

If fetchpwd is adding an extra newline you can remove newlines using

mypass=$(fetchpwd "$sourceserver" "$logginacct" | tr -d '\n')
  •  Tags:  
  • bash
  • Related