sh
sh copied to clipboard
syntax: confusing error when "function" is used in posix mode
-
error: Euler:~ #shfmt_v3.5.1_linux_arm64 -i 4 -ci -d -bn -sr 1.sh 1.sh:2:15: a command can only contain words and redirects; encountered ( Euler:~ #cat 1.sh #!/bin/sh function watch() { true }
-
no problem: Euler:~ #shfmt_v3.5.1_linux_arm64 -i 4 -ci -d -bn -sr 1.sh Euler:~ #cat 1.sh #!/bin/sh watch() { true }
I think you want to be using #!/bin/bash as your shebang, as function is a Bash feature. Or otherwise, explicitly pass in the -ln=bash flag. Although our error message here could probably be more helpful, so I think it's worth keeping this issue open for that improvement.
Thank you for your reply. I agree with you
I think you want to be using
#!/bin/bashas your shebang, asfunctionis a Bash feature. Or otherwise, explicitly pass in the-ln=bashflag. Although our error message here could probably be more helpful, so I think it's worth keeping this issue open for that improvement.
I'll keep this open for the sake of better errors :)