Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

syntax for assigning values to a variable

Posted on 2008-06-24
8
Medium Priority
?
1,055 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 200 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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 48

Accepted Solution

by:
Tintin earned 300 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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 …
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…

618 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