syntax for assigning values to a variable

very simple question, in a KornShell script, I want to assign a value to a variable, do I use single quote, double-quote, or what? What is the rule?

these two work, so no quotes at all
LOAD_TYPE=pde$1cov_mapd

trace_flag=FALSE - is this the boolean FALSE (aka reserved word), so it doesn't need quotes?

proposed:      
PLAN_TYPE=mapd - does this need quotes?

USER_FRIENDLY_PGM=MA-PD - does this need quotes, oftentimes the dash causes hiccups

USER_FRIENDLY_PGM=Med D - seems like this needs quotes since there is a space

LVL 1
Alaska CowboyAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
TintinConnect With a Mentor Commented:
Rules are:

1.  Use single quotes when you want to assign a literal value to a variable.
2.  Use double quotes when if the value is blank, has spaces or a variable name
3.  No quotes are needed if assigning a string or variable that has no spaces.

0
 
Alaska CowboyAuthor Commented:
Also, in this statement (which works in Production), why does ${LOAD_TYPE} have double-quotes?

Works:   if [ "${LOAD_TYPE}" != "pde41cov" ] && [ "${LOAD_TYPE}" != "pde43cov" ]

Would this work (no quotes on variable): if [ ${LOAD_TYPE} != pde41cov ] &&
0
 
ozoConnect With a Mentor Commented:
if [ "${LOAD_TYPE}" != "pde41cov" ]
would need " if you needed quotes for something like
LOAD_TYPE="a = b"
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Alaska CowboyAuthor Commented:
ok, sounds like double quotes are needed if there are spaces or special characters.

so is it true both of these work

LOAD_TYPE=mapd
LOAD_TYPE="mapd"

Thanks.
0
 
Alaska CowboyAuthor Commented:
Tintin, excellent, thanks.
0
 
ozoCommented:
3.  No quotes are needed if assigning a string or variable that has no spaces or quotes or $ or * or ? or [] or {} or \
0
 
Alaska CowboyAuthor Commented:
ozo, ok, thanks for the clarification
0
 
ozoCommented:
or < or > or ; or & or | or ( or )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.