${bindir} vs $bindir


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers ${bindir} vs $bindir
# 1  
Old 11-12-2003
${bindir} vs $bindir

Hi everybody,
I have been going through a shell scripting book and I have been given a suggestion that says

${bindir} has an advantage over $bindir in the following scenario:

bindir="/usr/local/bin"

exceptions="${bindir}/exc" is better than
exceptions="$bindir/exc" and that the latter might give errors.

But when I echoed them, I got the same result in both cases.

Can you explain me what the text book was trying to convey, and why I didn't get any errors?
# 2  
Old 11-12-2003
For this case it may not matter, but if you have something like

num="Number"

then

${num}3 and $num3 will give different results.
# 3  
Old 11-12-2003
I would always go with "${bindir}/exc" rather than "$bindir/exc" because the former is more readable. I use understandable variable names, blank lines, superfluous parentheses, etc for the same reason.

And yes, the more readable the code, the fewer the errors.... made by the programmmer. Write a complex program with dozens of variables but only use the letters x and y in your variable names. This won't matter to the computer, but it matters a lot to the programmer. You will have many more errors than if you had used readable variable names.
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question