Solved

syntax for assigning values to a variable

Posted on 2008-06-24
8
1,051 Views
Last Modified: 2013-12-26
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

0
Comment
Question by:Alaska Cowboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 1

Author Comment

by:Alaska Cowboy
ID: 21857674
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
 
LVL 84

Assisted Solution

by:ozo
ozo earned 50 total points
ID: 21858168
if [ "${LOAD_TYPE}" != "pde41cov" ]
would need " if you needed quotes for something like
LOAD_TYPE="a = b"
0
 
LVL 1

Author Comment

by:Alaska Cowboy
ID: 21858948
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 48

Accepted Solution

by:
Tintin earned 75 total points
ID: 21860457
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
 
LVL 1

Author Comment

by:Alaska Cowboy
ID: 21861618
Tintin, excellent, thanks.
0
 
LVL 84

Expert Comment

by:ozo
ID: 21861855
3.  No quotes are needed if assigning a string or variable that has no spaces or quotes or $ or * or ? or [] or {} or \
0
 
LVL 1

Author Comment

by:Alaska Cowboy
ID: 21861873
ozo, ok, thanks for the clarification
0
 
LVL 84

Expert Comment

by:ozo
ID: 21861905
or < or > or ; or & or | or ( or )
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question