${var//search/replace}
is a bash-only feature. It is not guaranteed to be present with /bin/sh
. Use ${var#prefix}
instead, which is part of the POSIX sh specification and so guaranteed to be offered by /bin/sh
.
#!/bin/sh
file=${1%.class}
echo "Trimmed suffix: $file"
file=${file#./}
echo "Also trimmed prefix: $file"
...if the parameter is ./FirstJavaProgram.class
, the output will be:
Trimmed suffix: ./FirstJavaProgram
Also trimmed prefix: FirstJavaProgram
By contrast, if you want to use bash-only features, start your script with #!/usr/bin/bash
, or #!/bin/bash
, #!/usr/bin/env bash
, etc. as appropriate.