Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
    
Do you also get a message saying "Permission denied"? –  Charo Jun 28 at 13:06
    
If so, as azzid told you, you will have to make the script executable. –  Charo Jun 28 at 13:09
1  
If one of the answers solved your issue please take a minute and click the check mark under the vote count to the left, this will signify to everyone that your issue's been resolved. –  terdon Jun 28 at 14:31

2 Answers 2

Try this instead:

:!./%

I use bash, so my error codes are different, but the path gets a bit of when you run % directly.

Also, you might need to run :!chmod u+x ./% before to make the script executable.

share|improve this answer
    
Thanks Sir,it worked –  Uchiha Itachi Jun 28 at 13:13

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 %
share|improve this answer
    
Thanks Sir,it worked –  Uchiha Itachi Jun 28 at 13:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.