The substitution you're using is not a basic POSIX feature (see here, in section 2.6.2 Parameter Expansion), and dash
doesn't implement it.
But you can do it with any of a number of external helpers; here's an example using sed
:
PORT="-p7777"
CAPITOLPORT=$(printf '%s\n' "$PORT" | sed 's/p/P/')
printf '%s\n' "$CAPITOLPORT"
BTW, note that I'm using printf '%s\n'
instead of echo
-- that's because some implementations of echo
do unpredictable things when their first argument starts with "-". printf
is a little more complicated to use (you need a format string, in this case %s\n
) but much more reliable. I'm also double-quoting all variable references ("$PORT"
instead of just $PORT
), to prevent unexpected parsing.
I'd also recommend switching to lower- or mixed-case variables. There are a large number of all-caps variable that have special meanings, and if you accidentally use one of those it can cause problems.