I have the following command in NPPExec:
NPP_SAVE
npp_exec "C:\bin\foo.sh"
Where foo.sh contains the following:
#! /bin/bash
echo "This is a test script"
This is the output from the NPPExec console:
NPP_SAVE: C:\bin\foo.sh
NPP_EXEC: "C:\bin\foo.sh"
#! /bin/bash
CreateProcess() failed with error code 2:
The system cannot find the file specified.
"This is a test script"
================ READY ================
I want NPP_EXEC to just run the script, and leave it alone after that. I had this working before, but my HD crashed, now I can't seem to get it working again.
Remove the sh-bang line (#!/bin/bash) from your code.
That line tells the process to look for an executable file named C:\bin\bash on your computer, then use that file to run the ensuing script. Apparently, the process can't find said file. But it shouldn't need to find it. Windows* can run your .sh file as an executable.
*(If you're using Notepad++, you're on Windows, right?)
Alternatively, put an executable file named "bash" in your folder "/bin", and let that "bash" file have the capability of running your shell script.
Related
I am trying to use git bash to run my .sh file that was generated using Makefile.
When running the command ./run.sh I get this message ./run.sh: line 1: /home/user/run: No such file or directory
To run a script file (using Git Bash), you do the following:
Add a "sh-bang" line on the first line (e.g. #!/bin/bash OR #!/usr/bin/env sh) this is how git bash knows a file is executable.
Use ./ (or any valid dir spec): ./script.sh
Note : any "sh-bang" will work
You are using git bash so I suppose you are using Windows.
As for me I always use shebang on my scripts. Depending on the content of your script, you may add one of the following lines at the first line of your script.
#!/bin/sh
#!/bin/bash
#!/usr/bin/perl
#!/usr/bin/tcl
#!/bin/sed
#!/usr/awk
#!/usr/bin/python
If you still have problems running the script with ./run.sh command, you may try to use sh run.sh (on Git bash) and it should execute the script just as ./run.sh does it on linux.
This error message says that the first line of the script tries to execute an executable program named run in your home directory, and this does not exist.
I don't know what run.sh is supposed to do, but if you want to execute it a program, you need to make sure that the program exists, for instance by creating it.
I have a simple Gruntfile that I want to be able to run from an icon in my OSX dock.
I have created a very simple shell script (launcher.sh) that I will save as an application so I can add it to my dock. It works great when I run it directly in my Terminal:
#!/usr/bin/env bash
$(grunt serve --open)
It also works fine with this shebang: #!/bin/bash
However when I call the shell script from an Automator workflow I get the following error:
launcher.sh: line 2: grunt: command not found
This is my Automator set up:
What am I doing wrong?
Update
If I put this in my launcher.sh file:
#!/bin/bash
`/usr/local/bin/grunt serve --open`
I get a different error in Automator: env: node: No such file or directory
But, as before, if I run the script directly in Terminal its fine - so I think #mklement0 is right about the PATH
Update 2
launcher.sh
#!/bin/bash
grunt serve --open
Automator
PATH="/usr/local/bin:$PATH"
~/Public/Sites/launcher.sh
Now I'm still getting an error popup when I run it in Automator, but it has no details - it just says:
The action "Run Shell Script" encountered an error.
The Log panel shows a blank entry. Is there a way to get more info? A verbose mode perhaps?
Update 3
So this is weird... if I use &> ~/log it works. Without it it fails.
But this is working, thanks #mklement0, it'll do for now
PATH="/usr/local/bin:$PATH"
cd ~/Public/Sites && ./launcher.sh &> ~/log
The problem is that the $PATH variable when running from Automator doesn't have the same entries as when running from Terminal.
Notably, /usr/local/bin is missing, which is where grunt is typically installed (if installed globally).
A simple workaround is to add the folder in which grunt is installed to your $PATH at the top of the Automator shell script:
PATH="/usr/local/bin:$PATH"
~/Public/Sites/Launcher.sh
Aside from that:
Your shell command, $(grunt serve --open), should be just grunt serve --open - no need for a command substitution ($(...) or `...`), as that would actually first execute the command and then try to execute the output from that command.
The default working dir. when running a shell script from Automator is ~ (your home folder), which may not be what your script expects; it looks like your script expects its own dir. to be the working dir., so use cd ~/Public/Sites && ./launcher.sh to invoke it.
Automator will report an error in case the shell script exits with a nonzero exit code; the error message will include the shell script's stderr output (and nothing else) - sounds like no stderr output is being produced in your case.
To capture all output for diagnostic purposes, use something like ./launcher.sh &> ~/log
On macOS 10.11 through at least 10.15 (as of this update), $PATH has the following value inside a shell script run from an Automator workflow: /usr/bin:/bin:/usr/sbin:/sbin
I'm trying to run an extremely simple bash script that runs some commands on the shell. For now, all it is composed of is:
#!/bin/bash
eos
Where "eos" is a perfectly legit command that runs perfectly fine on the server I'm using if I run it manually on the same shell.
However, when I chmod +x and execute this script, I get the error:
./cp.sh: line 21: eos: command not found
Does anyone have any idea why it won't submit these commands?
Thanks in advance!
What user is running the script? I suspect an environment or pwd issue, although permissions are a possibility.
Try using the full path to eos or setup the necessary environment in the script.
In unix shell "command not found" error comes when the directory at which command is located is not in PATH (an env variable) which is searched to locate the command.
The solution to this is either of any of the 2 approaches mentioned below
a) change PATH and export PATH variable either in shell startup files or user profiles
export PATH=$PATH:/eos-command-directory-location/
b) run the eos command in shell script you have developed with full path
So I have a .sh script (in Ubuntu):
#!/bin/bash
javac betz2.java
When I run it, it says:
Invalid flag: betz2.java
WHen run in terminal, it works just fine? why?
javac betz2.java
Maybe javac is not in the Bash path, but your command line is using a different shell that does have it. In your command line type echo $SHELL and you'll see if it is bash or not.
Did you edit your file in Windows and then opened it in a different operating system? (Linux). Carriage returns might be causing you trouble, just create a new file and paste your command.
I'm trying to reconstruct how to execute a bash shell .sh file on my Windows machine from within Notepad++ using NPPExec. (I've done this successfully before, but my HDD crashed and I don't recall how I did it previously.)
When it was working before, I would run the NPPExec script that called a .sh file, and it showed me the console output of the .sh file processing in Notepad++ as if it were processing in cygwin.
This is the example .sh file that I'm trying to get to work:
message="Testing"
echo $message
This file is located in the root of C:.
Failed Attempts:
None of the following three methods work:
Execute: C:\nppexec.sh
Response:
CreateProcess() failed with error code 193:
%1 is not a valid Win32 application.
Execute: npp_exec C:\nppexec.sh
Response:
message="Testing"
CreateProcess() failed with error code 2:
The system cannot find the file specified.
$message
Adding #! /bin/bash to the .sh file as the first line just causes an additional error when npp_exec is run:
NPP_EXEC: C:\nppexec.sh
#! /bin/bash
CreateProcess() failed with error code 2:
The system cannot find the file specified.
The solution was to call bash directly:
C:\cygwin\bin\bash --login -c "command.sh"
I have the same error while trying to execute a batch file on windows.
I resolved the problem by executing at first command cmd in console of notepad++, then E:\test.bat
I also have a mksnt installed on my window pc.
by starting at first the bash in console of notepad++, the test shell work well now
bash
C:\nppexec.sh
With a single keystroke I wanted to execute the shell script of the active Tab using Cygwin within notepad.
After few hours looking online and experimenting, I finally came up with
install NppExec plugin
Hit F6
paste the following code:
//save the file
NPP_SAVE
//redirect console output to $(OUTPUT) & silent mode
npe_console v+ --
//convert winpath to cygpath
D:\cygwin64\bin\bash -lc "cygpath \"$(FULL_CURRENT_PATH)\"
//execute the file
D:\cygwin64\bin\bash -lc "$(OUTPUT)"
Hope that save some time to some people
Use this Run command
C:\cygwin64\bin\bash.exe -l -c "cd \"$0\" ; echo $#; \"./$1\"; exec bash;" "$(CURRENT_DIRECTORY)" "$(FILE_NAME)"
You can save this command for later use from Run dialog box.
For git bash, change the path like this:
C:\Progra~1\Git\bin\bash -l -c "cd \"$0\" ; echo $#; \"./$1\"; exec bash;" "$(CURRENT_DIRECTORY)" "$(FILE_NAME)"