Parameter expansion instead of external commands

Use bash parameter expansion where possible rather than forked processes