'How to put single quotes in bash
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
'
Solution 1:[1]
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"
Solution 2:[2]
If fetchpwd is adding an extra newline you can remove newlines using
mypass=$(fetchpwd "$sourceserver" "$logginacct" | tr -d '\n')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Diego Torres Milano |
