Ubuntu – Unable to run shell script inside VI/VIM

command linescriptsvim

I am trying to run a shell-script say test from vim

#!/bin/sh 
echo good morning

Now when I am using :!%
I am getting a pop like

shell returned 1
Press ENTER or type command to continue

instead of good morning.

Someone please tell me what am I doing wrong. Do I have to change the path,if so how to do it. Running it from my home folder

Best Answer

That will only work if the script file's permissions have the executable bit set. You can do this through Vim

:! chmod +x %
:! ./%

Or you could just run it through its interpreter manually:

:! bash %
Related Question