You are not logged in.
I'm finding that the simplest solution to a problem in a Makefile that I'm writing is to use the ${var#param} parameter expansion. How portable is this? I've tried using both bash and sh and they both work as expected, but I'd like to make sure that this is a standard feature present in all relevant shells.
$ bash -c 'var="Hello";/usr/bin/echo ${var#Hell}'
o
$ sh -c 'var="Hello";/usr/bin/echo ${var#Hell}'
o
Last edited by jakobcreutzfeldt (2013-03-13 15:44:03)
Offline
fish looks problematic, but zsh and dash are fine:
$ zsh -c 'var="Hello";/usr/bin/echo ${var#Hell}'
o
$ dash -c 'var="Hello";/usr/bin/echo ${var#Hell}'
o
$ fish -c 'var="Hello";/usr/bin/echo ${var#Hell}'
fish: Unknown command “var=Hello”. Did you mean “set var Hello”? For information on assigning values to variables, see the help section on the set command by typing “help set”.
Standard input: var="Hello";/usr/bin/echo ${var#Hell}
^
fish: Could not expand string “${var”
Standard input: var="Hello";/usr/bin/echo ${var#Hell}
^
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Offline
Ok thanks. It seems that fish isn't Bourne-compatible (given the way it handles vars).
Offline