anish
anish

Reputation: 7422

Using <<< throws error on sh shell not in bash

In Sh

[SunOs] /opt # sh
[\h] \w \$ read -a array <<< "1 2 3";echo ${array[1]}
syntax error: `<' unexpected

In Bash

[SunOs] ~ # bash
[SunOs] ~ # read -a array <<< "1 2 3";echo ${array[1]}
2

Why the Error thorwn in "sh" shell, i'm using SunOS 5.10 Generic_147440-10 sun4v sparc sun4v

Upvotes: 2

Views: 96

Answers (2)

cato
cato

Reputation: 11

As a workaround you may use the builtin POSIX command set to assign your arguments to the positional parameters $1, $2, ... or the positional parameter array $@ respectively

{
IFS="`printf ' \n\t'`"
export IFS
printf '%s' "$IFS" | od -b
set -- `printf '%s' "1 2 3"`
echo "$0"
echo "$1"
echo "$2"
echo "$3"
echo "$@"
}

Upvotes: 1

devnull
devnull

Reputation: 123628

Herestrings aren't supported in sh.

This causes the error when you try to run it using sh.

Upvotes: 3

Related Questions