What is the POSIX shell equivalent of bash <<<

Bitdiot

I have a variable that looks sort of like this:

msg="newton apple tree"

I want to assign each of these words into separate variables. This is easy to do in bash:

read a b c <<< $msg

Is there a compact, readable way to do this in POSIX shell?

that other guy

To write idiomatic scripts, you can't just look at each individual syntax element and try to find a POSIX equivalent. That's like translating text by replacing each individual word with its entry in the dictionary.

The POSIX way of splitting a string known to have three words into three arguments, similar but not identical to read is:

var="newton apple tree"

set -f
set -- $var
set +f
a=$1 b=$2 c=$3

echo "$a was hit by an $b under a $c"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is the bash equivalent of Python's all?

From Dev

What is the equivalent of "-" from Bash in Windows batch?

From Dev

How to test if string matches a regex in POSIX shell? (not bash)

From Dev

What's the Windows command shell equivalent of Bash's `true` command?

From Dev

What's the best way to embed a Unicode character in a POSIX shell script?

From Dev

What is the closest Windows equivalent to the POSIX wait mechanism?

From Dev

What is the PowerShell equivalent of bash's exec()?

From Dev

What is Linux/POSIX equivalent of VirtualAlloc with MEM_TOP_DOWN?

From Dev

POSIX-compliant shell equivalent to Bash "while read -d $'\0' ..."?

From Dev

POSIX shell equivalent to <()

From Dev

What is Ubuntu's equivalent of Windows shell:startup?

From Dev

What is Ubuntu's equivalent of Windows shell:startup?

From Dev

What is the equivalent of bash's !$ and !! in the fish shell?

From Dev

what is the zsh equivalent of bash's export -f

From Dev

What's the Bash equivalent of "cmd /c"

From Dev

How to test if string matches a regex in POSIX shell? (not bash)

From Dev

What is the equivalent of Bash's cat -n in PowerShell?

From Dev

What is the meaning of $0 in the Bash shell

From Dev

What is the bash equivalent of the where cmdlet?

From Dev

What is the equivalent of `type` (used in bash and sh) in csh?

From Dev

What is the bash equivalent of DOS's pause command?

From Dev

Set data structure equivalent in bash shell?

From Dev

zsh and POSIX equivalent of bash's `{var}>&1`

From Dev

Bash equivalent .bash_logout for FISH shell

From Dev

What is the equivalent __LINE__ (php) in bash ?

From Dev

bash and POSIX shell difference in dot command

From Dev

What is the bash equivalent of zsh vared command?

From Dev

POSIX equivalent to column -t

From Dev

What is the POSIX shell version of this bash "while" statement?

Related Related

  1. 1

    What is the bash equivalent of Python's all?

  2. 2

    What is the equivalent of "-" from Bash in Windows batch?

  3. 3

    How to test if string matches a regex in POSIX shell? (not bash)

  4. 4

    What's the Windows command shell equivalent of Bash's `true` command?

  5. 5

    What's the best way to embed a Unicode character in a POSIX shell script?

  6. 6

    What is the closest Windows equivalent to the POSIX wait mechanism?

  7. 7

    What is the PowerShell equivalent of bash's exec()?

  8. 8

    What is Linux/POSIX equivalent of VirtualAlloc with MEM_TOP_DOWN?

  9. 9

    POSIX-compliant shell equivalent to Bash "while read -d $'\0' ..."?

  10. 10

    POSIX shell equivalent to <()

  11. 11

    What is Ubuntu's equivalent of Windows shell:startup?

  12. 12

    What is Ubuntu's equivalent of Windows shell:startup?

  13. 13

    What is the equivalent of bash's !$ and !! in the fish shell?

  14. 14

    what is the zsh equivalent of bash's export -f

  15. 15

    What's the Bash equivalent of "cmd /c"

  16. 16

    How to test if string matches a regex in POSIX shell? (not bash)

  17. 17

    What is the equivalent of Bash's cat -n in PowerShell?

  18. 18

    What is the meaning of $0 in the Bash shell

  19. 19

    What is the bash equivalent of the where cmdlet?

  20. 20

    What is the equivalent of `type` (used in bash and sh) in csh?

  21. 21

    What is the bash equivalent of DOS's pause command?

  22. 22

    Set data structure equivalent in bash shell?

  23. 23

    zsh and POSIX equivalent of bash's `{var}>&1`

  24. 24

    Bash equivalent .bash_logout for FISH shell

  25. 25

    What is the equivalent __LINE__ (php) in bash ?

  26. 26

    bash and POSIX shell difference in dot command

  27. 27

    What is the bash equivalent of zsh vared command?

  28. 28

    POSIX equivalent to column -t

  29. 29

    What is the POSIX shell version of this bash "while" statement?

HotTag

Archive