Yes <<<
is a zsh operator now also supported by a few other shells (including bash
), but it still hasn't been added in the standard specification of the sh
language and a few sh
implementations still don't support it.
To remove a trailing /
from the contents of a variable it's just:
output=${output%/}
If instead you wanted to remove /
from the end of every line in $output
like that zsh
code does, you could do:
output=$(printf '%s\n' "$output" | sed 's|/$||')
Or using the standard here-doc instead of zsh's here-string:
output=$(
sed 's|/$||' << EOF
$output
EOF
)
Shells that support <<<
are:
zsh
, since 1991
- Byron Rakitzis's clone of
rc
for Unix (though doesn't add an extra newline), since 1991 as well, and derivatives (es
, akanga
)
ksh93
, since 2002
bash
, since 2002
mksh
, since 2008
yash
, since 2009 (not when called as sh
)
sh
implementations that don't support it as of May 2020 include the Bourne shell, ksh88
, ash
and its derivatives (dash
, the sh
of busybox, FreeBSD, NetBSD), pdksh
, posh
, OpenBSD sh
, bosh
.
<<<
is a bash/ksh/zsh feature not present in sh. – glenn jackman May 5 '20 at 20:07