I got the following variable:
set location "America/New_York"
and want to display only the part before the /
(slash) using fish
shell syntax.
America
Using bash, I was simply using a parameter expansion:
location="America/New_York"
echo ${location##*/}"
How do I do that in a fish
-way?
Since fish 2.3.0, there's a builtin called string
that has several subcommands including replace
, so you'll be able to do
string replace -r "/.*" "" -- $location
or
set location (string split "/" -- $location)[1]
See http://fishshell.com/docs/current/commands.html#string.
Alternatively, external tools like cut
, sed
or awk
all work as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With