Question

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

Was it helpful?

Solution

Herestrings aren't supported in sh.

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

OTHER TIPS

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 "$@"
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top