Operating System - HP-UX
1834492 Members
3301 Online
110067 Solutions
New Discussion

difference between $LOGDIR and ${LOGDIR} ?

 
SOLVED
Go to solution
Sammy_2
Super Advisor

difference between $LOGDIR and ${LOGDIR} ?

Is there a difference in parentheses being out as oppose to not having them at all.
we are trying to run a job via cron. (hpux 11.11)and have a mixture of these parentheses and want to make sure we get the same result in all cron entries.


Please explain.
good judgement comes from experience and experience comes from bad judgement.
6 REPLIES 6
Rodney Hills
Honored Contributor
Solution

Re: difference between $LOGDIR and ${LOGDIR} ?

Usually they are used when the variable is embedded with other text.

example-
echo ${LOGDIR}A $LOGDIRA

Will display variable LOGDIR followed with an A, while LOGDIRA the shell will think it is the variable name.

{} are also used for arrays and some other operations that are available on variables. See man ksh for more.

HTH

-- Rod Hills
and
${LOGDIR}A
There be dragons...
Devender Khatana
Honored Contributor

Re: difference between $LOGDIR and ${LOGDIR} ?

Hi,

It is used for defining a new variable according to the value of previous variable. By defining it like this shell understand that this is a variable previously defined.

For ex.
server1:/home/hp/>>export LOGNAME=123
server1:/home/hp>>echo $LOGNAME
123
server1:/home/hp>>export LOGNAME1=${LOGNAME}newlogname
server1:/home/hp>>echo $LOGNAME1
123newlogname

(The value is new variable is appended to previous value of similar variable)

Some scripting experts will describe it better otherwise.

HTH,
Devender
Impossible itself mentions "I m possible"
A. Clay Stephenson
Acclaimed Contributor

Re: difference between $LOGDIR and ${LOGDIR} ?

If you use the {}'s each and every time, you will never get into trouble (parsing-wise); the converse is not true. It's a very good habit to learn.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: difference between $LOGDIR and ${LOGDIR} ?

Hi Sammy:

As noted, bounding your variable names with curly braces avoids ambiguitites in what you versus the shell interpret as the variable name.

Personally, I consider it simply good practice to always encapsulate variables within curly braces in shell programming.

Regards!

...JRF...
Jeff_Traigle
Honored Contributor

Re: difference between $LOGDIR and ${LOGDIR} ?

Also note you're asking about braces (i.e. {}), not parentheses (i.e. ()). Big difference in how the shell interprets these. It's best to say what you mean in cases where you aren't typing what you're really referencing.

${something} represents the value of the some variable.

$(something) represents executing whatever "something" is. This is also represented as `something` in older shells and is still used for backwards compatibility.
--
Jeff Traigle
Sammy_2
Super Advisor

Re: difference between $LOGDIR and ${LOGDIR} ?

Point taken. thanks to Rod and Devender for providing examples which was reinforced by JRF and Clay. Jeff made another good pt about parentheses.

Thanks to all
good judgement comes from experience and experience comes from bad judgement.