back toc next

Parameter Expansion

$parameter
${parameter}

Example:

foo="some text"
foobar="another text"
echo $foo
echo $foobar
echo ${foo}bar

There are many extensions to this notation, which permit textmanipulation from withinn the shell. See PARAMETER EXPANSION in the fine manual.

Example: Renaming every .JPG to .jpeg

for i in *.jpg; do
    mv -i "$i" "${i%.JPG}.jpeg"
done
Note: always use quotes around variables which can hold unknown data. This prevents the shell to split the string into multiple arguments.
Problem 1: (which isn't a real problem) If there is no file .JPG, a error is issued by mv.
Problem 2: If a filename contains a newline, this solution breaks.