I tried to use FreeBSD.
The FreeBSD root
user uses csh
by default.
user@freebsd-13:~ $ echo $SHELL
/bin/csh
I know that setting a variable via $()
does not work in csh
.
root@freebsd-13:~ # export test=$(echo hello3)
Illegal variable name.
I want to do something like that
root@freebsd-13:~ # sh -c "export test=$(echo hello3)"
Illegal variable name.
root@freebsd-13:~ #
And it does not work either... However, this works:
root@freebsd-13:~ # sh -c "echo "hello""
hello
Or this works as well but in the scope of sh
:
root@freebsd-13:~ # sh
# export test=$(echo hello3)
# echo $test
hello3
# exit
root@freebsd-13:~ # echo $test
test: Undefined variable.
root@freebsd-13:~ #
Another attempt to set a variable via sh
:
root@freebsd-13:~ # sh -c "export test=`echo hello5`"
root@freebsd-13:~ # echo $test
test: Undefined variable.
root@freebsd-13:~ # sh -c "echo "$test""
test: Undefined variable.
root@freebsd-13:~ #
root@freebsd-13:~ # /bin/sh -c "export test=`echo hello3`"
root@freebsd-13:~ # echo $test
test: Undefined variable.
root@freebsd-13:~ # /bin/sh -c "echo "$test""
test: Undefined variable.
root@freebsd-13:~ #
Tried to source it:
root@freebsd-13:~ # . sh -c "export test=$(echo hello3)"
Illegal variable name.
root@freebsd-13:~ #
root@freebsd-13:~ # . sh -c "export test=`echo hello3`"
.: Command not found.
root@freebsd-13:~ #
root@freebsd-13:~ # source sh -c "export test=`echo hello3`"
sh: No such file or directory.
root@freebsd-13:~ #
root@freebsd-13:~ # source /bin/sh -c "export test=`echo hello3`"
Unmatched '"'.
root@freebsd-13:~ # source /bin/sh -c "export test=$(echo hello3)"
Illegal variable name.
root@freebsd-13:~ #
root@freebsd-13:~ # source /bin/sh -c "export test="$(echo hello3)""
Illegal variable name.
root@freebsd-13:~ #
How should it be done properly?