i'm coding a simple bash script and i found this error syntax error at line XX `(' unexpected my code:
function myfun(){
echo XXXX
echo YYYY
read choice
}
choice=$(myfun)
where is the error. i used the ShellCheck and no errors were detected.
Make sure you are running the script with bash. That error is a commonly seen dash shell error.
I suspect the first line of your script is not #!/bin/bash, i.e. you may have left out the shebang line entirely resulting in the default shell being used (which will often be dash especially on Debian derived Linuxes where /bin/sh -> dash).
Try running this:
#!/bin/bash
myfun()
{
echo XXXX
echo YYYY
read choice
}
choice=$(myfun)
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