Skip to main content

Hello!



I try to automate the creation of certificate request files. Everything works fine so far, except the correct handover of the former entered values for the request file.



I have eight variables with strings, this strings could have spaces, like "John Appleseed".
I use this line to generate the request file:



printf '%s
' $countrycode $state $city $company $department $name $email $nothing $nothing | openssl req -new -key /Users/Shared/Greentube/CertificateRequest/Files/RSA.key -out /Users/Shared/Greentube/CertificateRequest/Files/REQUEST.csr


It works like expected as long as the variables don't contain any spaces, but it gets completely chaotic if there are spaces, because it does the "new line" after a word ends, not after the complete value of the variable ends. So "JohnAppleseed" would work, but "John Appleseed" would only enter "John" to one field and "Appleseed" to the next..



I'm sure its just an error in my syntax, I'm not that familiar with scripting... maybe someone can help?



Thanks!



Greetings,
Marco

Got it!



This works for me:



echo "$countrycode
$state
$city
$company
$department
$name
$email
$nothing
$nothing" | openssl req -new -key /Users/Shared/Greentube/CertificateRequest/Files/RSA.key -out /Users/Shared/Greentube/CertificateRequest/Files/REQUEST.csr

fyi: double-quoting the variable names in the original example would do it



printf '%s
' "$countrycode" "$state" ...