variable interpolation in shell

This is probably a very basic question but for some reason I seem to be over looking the obvious.

I have a variable called filepath=/tmp/name

To access the variable I know that I can do this $filepath

In my shell script I attempted to do something like this (The back ticks are intended)

`tail -1 $`

This line fails, duuh! because the variable is not called $

How do I append to the variable name? Please note that back ticks are intended for the expression evaluation








_ is a valid character in identifiers. Dot is not, so the shell tried to interpolate $filepath_newstap.

You can use set -u to make the shell exit with an error when you reference an undefined variable.

Use curly braces around the variable name:

`tail -1 ${filepath}`

In bash: tail -1 ${filepath}

Need Your Help

Python: Assign Value if None Exists

python python-2.7 variable-assignment language-comparisons

I am a RoR programmer new to Python. I am trying to find the syntax that will allow me to set a variable to a specific value only if it wasn't previously assigned. Basically I want: