This uses "process substitution" (<()) and a "heredoc" (cat << EOF...EOF) to open a new bash process where it runs the startup "file" (--rcfile) containing alias foo="echo hey you. Here is the command:
bash --rcfile <(
cat << EOF
alias foo="echo hey you"
EOF
)
It works on Ubuntu just fine, as you can see here:
$ bash --rcfile <(
> cat << EOF
> alias foo="echo hey you"
> EOF
> )
$ foo
hey you
$ alias
alias foo='echo hey you'
However, when I try to run this on certain embedded Linux devices, I get the following error. Why? How do I make it run there too?
-sh: syntax error: unexpected "("
Full output:
$ bash --rcfile <(
-sh: syntax error: unexpected "("
$ cat << EOF
> alias foo="echo hey you"
> EOF
alias foo="echo hey you"
$ )
-sh: syntax error: unexpected ")"
In case this helps, here are my which bash and bash --version outputs on Ubuntu vs the embedded Linux device:
# 1. Ubuntu
$ which bash
/bin/bash
$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
# 2. Embedded Linux device
$ which bash
/bin/bash
$ bash --version
GNU bash, version 5.0.16(1)-release (aarch64-buildroot-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
This is related but does not seem to be a duplicate: dash reports 'Syntax error: "(" unexpected' when using process substitution.