I work with SQL queries in Sublime 2. I have a custom script that takes sql filename as an argument, uploads it to the server, downloads the query result and converts it to valid csv file. It works, and it's very useful.
However, when I tried to set up a build system for Sublime Text 2 using this script, I get errors. Here's my sublime-build file:
{
"cmd" : ["exec_sql.sh", "$filename"],
"selector" : "source.sql",
"path" : "/Users/username/sql"
}
SQL files and exec_sql script are both located in /Users/username/sql/ folder. Here's what I get:
/Users/username/sql/exec_sql.sh: line 9: which: command not found
/Users/username/sql/exec_sql.sh: line 16: basename: command not found
/Users/username/sql/exec_sql.sh: line 19: username#hostname.com:/tmp/: No such file or directory
/Users/username/sql/exec_sql.sh: line 24: ssh: command not found
/Users/username/sql/exec_sql.sh: line 25: username#hostname.com:/tmp/.csv: No such file or directory
[Finished in 0.0s with exit code 127]
It seems that despite being a command-line script, sh file is being interpreted as something else. How do I fix it?
I think that the problem can be solved if your custom script is added to the system path (to the BIN directory).
I am going to use a detailed example that i have used succesfully.
Be sure that your custom script is marked as executable and has got the shebang. A simple script that includes the basename command that fails in your example (i have called it test_basename.sh):
#!/bin/bash
echo $1
basename $1
Make a symlink to include the script in the BIN directory so it can be executed in any folder. In my Ubuntu i do it with this command:
sudo ln -s /Users/username/sql/test_basename.sh /usr/bin/test_basename.sh
Check the script in the console in any directory
cd /tmp
test_basename.sh some-filename
Restart Sublime Text
Create a build system that uses the simple script. I have used $file as an example. Other options are in the documentation.
{
"cmd" : ["test_basename.sh", "$file"]
}
Open a file in Sublime Text and run the build system created.
If you don't want to create a symlink use a variable like $project_path or $file_path
{
"shell_cmd": "./do.sh",
"shell": true,
"working_dir": "$project_path"
}
reference for variables: sublimeText docs
I was able to create a general purpose Bash build system for Sublime Text 2:
Create a new Build System
Use the following code:
{
"cmd": ["/path/to/bash-build.sh", "$folder"],
"shell": true,
"working_dir": "$folder",
"windows": {
"cmd": ["C:\\path\\to\\bash-build.sh", "$folder"]
}
}
Save it as bash.sublime-build
Create a new shell script using your editor of choice and paste the following code into it:
#!/bin/env bash
echo "Start building..."
if [ -f $1/build.sh ]; then
cd $1
build.sh
cd -
else
echo "File doesn't exist: $1/build.sh"
fi
echo "Done."
exit $?
Save it as bash-build.sh in the same folder that you reference in the Sublime Build System
Open a folder in Sublime (note: on Windows, build systems seem broken when Sublime is opened from the command line)
Create a new text file and save it as build.sh into the root folder opened in Subilme
In build.sh, go crazy:
#!/bin/env bash
# do some crazy, custom build
exit $?
I've started using this in conjunction with Pandoc to generate HTML files from Markdown files.
It seems like you are on Mac. I had the same problem before I realized that the System path variable is wrong.
I fixed it the following way.
First, get the current PATH by pasting this in terminal (without first $):
$ echo $PATH
Copy this path (it will look something like this: /opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/opt/local/bin:/opt/local/sbin)
Now edit the build system to include this path (the path variable you use should be actually a working_dir):
{
"cmd" : ["exec_sql.sh", "$filename"],
"selector" : "source.sql",
"working_dir" : "/Users/username/sql",
"path": "PASTE $PATH VALUE HERE"
}
And it should work now. At least it helped me.
Related
I am working on juptyter notebook in my VSCODE and when I try to run a command line in a cell as the following:
!'directory of fsl software' -I 'path of the mask in the MNI space' -o 'path of output file -w 'path of transformation from MNI to subjects mask' -r 'path of subject mask' --interp=nn
However, when I run the code, I obtain the error:
ERROR:: Environment variable FSLOUTPUTTYPE is not set! Please make sure that the appropriate configuration file is sourced by your shell (e.g. by putting it in .profile). e.g. bash or sh users add the line ". ${FSLDIR}/etc/fslconf/fsl.sh" e.g. tcsh or csh users add the line "source ${FSLDIR}/etc/fslconf/fsl.csh"
As it indicates, I open on VSC the file .bash_profile in the editor and copy:
FSLDIR=/usr/local/fsl . ${FSLDIR}/etc/fslconf/fsl.sh PATH=${FSLDIR}/bin:${PATH} export FSLDIR PATH
and, after saving the .bash_profile file and re running the line, it still doesn't work. Any idea?
I downloaded the Conda package of fslpy but I didn't use it because I'm running a command line and also I checked the dimensions of the files I was working with and that's not either the problem. I tried to download the VSCode extension in the remote server I am working with of FSharo fsl and fsy but obtained no results
We are facing very strange issue in running Shell Script file from 'QT' .pro file on Mac system(For our cross platform Qt project).
Same .pro file is working fine on Ubuntu machine without any issues.
We have following command for running script file which compiles .ts(Typescript) files into .js(javascript) files.
# TypeScript Compilation
{
PRE_BUILD_FILE = "$${PWD}/external/TSbuild/compileTS.sh"
DUMMY_DEPS = .
PreBuildEvent.input = DUMMY_DEPS
PreBuildEvent.output = DUMMY.txt
PreBuildEvent.commands = $$PRE_BUILD_FILE
PreBuildEvent.name = running Pre-Build steps...
# "target_predeps" tells qmake that the output of this needs to exist before we can do the rest of our compilation.
PreBuildEvent.CONFIG += no_link no_clean target_predeps
QMAKE_EXTRA_COMPILERS += PreBuildEvent
}
our script file looks like this
BASEDIR=$(dirname "$0")
echo "===============================================";
echo "Script Directory is: " $BASEDIR;
echo "===============================================";
tsc -p "$BASEDIR/tsconfig.json";
cd $BASEDIR/../../web/js/;
rm -r autogen_*.js;
rename 's/^/autogen_/' *.js;
exit 0;
We are getting following error while building code
'tsc' command not found.
'rename' command not found.
Note 1: Same script is running fine, if we run it from terminal using command in that directory or from other directory giving path.
$sh compileTS.sh
Note 2: If we change script file in following way.
BASEDIR=$(dirname "$0")
echo "===============================================";
echo "Script Directory is: " $BASEDIR;
echo "===============================================";
/usr/local/bin/tsc -p "$BASEDIR/tsconfig.json";
cd $BASEDIR/../../web/js/;
rm -r autogen_*.js;
/usr/local/bin/rename 's/^/autogen_/' *.js;
exit 0;
We are getting error message.
env: node: No such file or directory
Meaning script file was not able to find path of 'tsc'. Now file is not finding path of 'node'. means need to give complete path of command.
Note 3:
Same .pro file code is building without any issues on Linux. Linux we faced small issues, due to calling of script file.
PreBuildEvent.commands = .$$PRE_BUILD_FILE
Removed '.' to make it work.
PreBuildEvent.commands = $$PRE_BUILD_FILE
as ‘.’ causes running script in same directory as calling process.
Note 4: We also had try with calling script file in different way, nothing helped
PreBuildEvent.commands = .$$PRE_BUILD_FILE
PreBuildEvent.commands = sh $$PRE_BUILD_FILE
Note 5: Even updating 'PATH' variable, updating 'bash_profile' didn't helped. Setting up environment variable
Please guild us resolving this issue, may be some small mistake due to limited knowledge in Shell script and way of calling Shell script in mac system.
I am trying to start my cli tool via the package.json bin property.
I have the following:
...
"name": "mycli",
"bin": "./bin/mycli",
...
When I open the cmd in the package path and type: "mycli" it says that the command is not recognized.
Should I run an npm command? or use the scripts property? am I trying to access the bin property incorrectly?
Try to specify the name of your cli tool in the bin property, like:
"bin": {
"mycli": "./bin/mycli" // or "/bin/mycli.js" if it's a .js file
}
Then, run npm link, from inside your project folder, to create a global symbolic link to the current folder.
Don't forget to add the "preferGlobal": "true" property just before the bin property in your package.json file, in order to warn users to install your module globally.
Whenever I was trying to get my app to link, I kept running into problems on Windows where the generated scripts that would execute on path would try to run the *.js file using the default Windows executable (I don't know what that would be). I'm not sure why. I think it might be because it is a JavaScript file. However, I compared the generated scripts to some of the other modules I had installed, and figured out that if I made the bin file referenced by the package.json act as though it were to be executed on a *nix machine, npm would automatically try and add the call to node.
For example:
If my package.json looks like this:
myapp/package.json
"name": "myapp",
"bin": {
"myapp": "./bin/myapp"
}
My referenced bin file looks like this:
myapp/bin/myapp
#!/usr/bin/env node
require("../server.js");
The 2 generated executable files that appear in %APPDATA%\npm show up as follows by running the command npm link from within the myapp directory (which would have package.json in the root):
myapp
#!/bin/sh
basedir=`dirname "$0"`
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/node_modules/myapp/bin/myapp" "$#"
ret=$?
else
node "$basedir/node_modules/myapp/bin/myapp" "$#"
ret=$?
fi
exit $ret
myapp.cmd
#IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\node_modules\myapp\bin\myapp" %*
) ELSE (
node "%~dp0\node_modules\myapp\bin\myapp" %*
)
Bear in mind, I didn't need to make the 2 files above explicitly, I just needed to have the file to be executed as the bin file in the package.json. npm did the file creation.
Line Endings
One other thing to note that I ran into while using this method, make absolutely sure that your line endings are correct. I noticed that my bin was erroring with: ": No such file or directory" whenever I installed on *nix machines because there was an incorrect line ending. Thanks to View line-endings in a text file for example of how to print visible line endings.
For example, if you run cat -e PATH_TO_BIN and get something like this:
#!/usr/bin/env node^M$
^M$
require("../index.js");^M$
You're using the wrong line endings. If you get something like this:
#!/usr/bin/env node$
$
require("../index.js");$
Those should be the right line endings.
If you put
#!/usr/bin/env node
in the first line of your script, npm will create the necessary wrapper scripts.
Answer from Rodrigo Medeiros works for me, but only if I have too the shebang line at the .js file.
There I had another issue. I have node.js installed at c:\Program files\nodejs, and this was my shebang line:
#!c:/program files/nodejs/node
This didn't work, because the blank space. This was the correct one:
#!c:/progra~1/nodejs/node
I'm trying to learn to write shell scripts and use the Terminal.
In Users/user/Development/linux I've got a script called sysinfo_page.
So I'm in the linux folder in the terminal and I can see the sysinfo_page when I type the ls command.
However, when I enter the following command:
sysinfo_page > sysinfo_page.html
I receive the following message:
-bash: sysinfo_page: command not found
How do I resolve this?
If you want to run a script file form the current directory, you have to write ./ before your script name:
./script.sh
Your command may not be an executable file. Try this:
chmod +x sysinfo_page
./sysinfo_page > sysinfo_page.html
The first line will set the eXecutable flag on the file, the second will run it from the current dir. Note that if you want to run a file in the current directory and that dir is not included in your PATH, you need to prepend ./ or else the shell won't find it.
When i login to the cygwin terminal and type:
cd "cygdrive/c/existing/path"
it tells me, "no such file or directory". i am sure the path exists... do i miss a special cygwin package, or do i have a false configuration? i am puzzled...
It behaves the same when i try to call the cygwin bash from a windows batch file.
what i basically want to do is creating a windows batch file which starts cygwin and executes a shell script with a specified working directory as its described in this blog post: http://blog.dotsmart.net/2011/01/27/executing-cygwin-bash-scripts-on-windows/
my batch file seems to work, it does the following command:
%_CYGBIN%\bash.exe --login "cd %_CYGPATH%" "./%_CYGSCRIPT%"
but cygwin won't execute the 'cd' command. The console output of my batch file is:
/usr/bin/bash: cd /cygdrive/c/existing/path: No such file or directory
cd '/cygdrive/c/existing/path'
# ^
# \
# --- need forward slash (/) before the "c"