A contrived example... given
FOO=\"/foo/bar/baz\"
this works (in bash)
BAR=$(basename $FOO) # result is BAR=\"baz\"
BAZ=${BAR
Modified forms of parameter substitution such as ${parameter#word}
can only modify a parameter, not an arbitrary word.
In this case, you might pipe the output of basename
to a dd command, like
BAR=$(basename -- "$FOO" | dd bs=1 count=1 2>/dev/null)
(If you want a higher count, increase count
and not bs
, otherwise you may get fewer bytes than requested.)
In the general case, there is no way to do things like this in one assignment.