Skip to main content
Solved

Scripting question: Giving strings with spaces to a command


mkolb
Forum|alt.badge.img+8
  • Contributor
  • 33 replies

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

Best answer by mkolb

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
View original
Did this topic help you find an answer to your question?

2 replies

mkolb
Forum|alt.badge.img+8
  • Author
  • Contributor
  • 33 replies
  • Answer
  • July 25, 2017

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

Forum|alt.badge.img+7
  • Contributor
  • 50 replies
  • July 25, 2017

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

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings