I want to execute Zsh function command in Bash script. Here is an example:
~/.zshrc
hello () {
echo "Hello!"
}
hello.sh
#!/bin/bash
hello
executing above bash script in zsh
(zsh) $ ./hello.sh
hello command not found
I also tried with heredocs:
#!/bin/bash
/bin/zsh - <<'EOF'
hello
EOF
executing above script with heredocs also says command not found error.
Any suggestions?
Thanks!
The ZSH shell is an extended version of the Bourne Again Shell; thus, most commands and scripts written for bash will work on ZSH. The ZSH shell provides full programming language features such as variables, control flow, loops, functions, and more.
Zsh has floating-point support that Bash does not possess. Hash data structures are supported in Zsh that are not present in Bash. The invocation features in Bash is better when comparing with Zsh. The prompt look can be controlled in Bash, whereas Zsh is customizable.
You can use it like that :
#!/bin/bash
/bin/zsh -i -c hello
-i
: Force shell to be interactive
Then, if the shell is interactive, commands are read from /etc/zshrc
and then $ZDOTDIR/.zshrc
(this is usually your $HOME/.zshrc
)
-c
: Run a command in this shell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With