How to read environmental variable in bash that contains spaces and possibly other characters that need to be escaped?
I have a file server.env
PUBLIC_KEY=ssh-rsa whatever+whatever+8whatever/whatever+p+whatever user@alans-MacBook-Pro.local
I am trying to read this file into bash script as an environmental variable:
export $(cat server.env | xargs)
I am getting an error:
-bash: export: `user@alans-MacBook-Pro.local': not a valid identifier
OK, trying to quote the value in server.env:
PUBLIC_KEY='ssh-rsa whatever+whatever+8whatever/whatever+p+whatever user@alans-MacBook-Pro.local'
- the same error
Double quote:
PUBLIC_KEY="ssh-rsa whatever+whatever+8whatever/whatever+p+whatever user@alans-MacBook-Pro.local"
- also errors
What am I missing here?