osx terminal syntax emulation on windows for node scripts - windows

So I have a package json file that was built with osx in mind and it contains scripts for installs and builds. A lot of the scripts in that file have osx terminal specific syntax. Is there a way to emulate that terminal in windows so that syntax is read properly?
P.S. I've tried cygwin mintty (now called cygwin64 terminal), but still have the same issues.
EDIT My intention is not to maintain two files that essentially do the same thing and because we started off only using npm package manager I really don't want to introduce a task runner at this point.
EDIT 9/15/15
Here's an example of cygwin not emulating syntax:
NODE_ENV=production bin/build.sh in linux (ubuntu) will assign "production" to the node_env var and then execute the shell file build.sh, but in windows this syntax will cause errors with the var assignment and with the execution of the shell script file unless I use this syntax: setx NODE_ENV production&&bash bin/build.sh

OS X is based on BSD, so the closest approximation would be using a BSD VM.

Related

What's the difference between Git bash and WSL

I just installed Git SCM on my Windows machine. My machine had Node installed earlier. I am able to use node -v in git bash. But, Why I am able to use windows applications inside Git Bash and not in WSL Bash.
Inside WSL Bash-
hello#comp:~$ node -v
Command 'node' not found, but can be installed with:
sudo apt install nodejs
Inside Git Bash-
hello#comp MINGW64
$ node -v
v12.10.0
WSL is an a Linux like compatibility layer. You run Linux applications on top of WSL and they think they are running natively on Linux while the system calls are being translated to Windows OS system calls (WSL2 -- not yet released -- is a full Linux kernel running inside Windows). You do get to access Windows files through /mnt/c/... but that's about all you can expect in terms of Windows-Linux interoperability.
Git-bash, on the other hand, is a Windows app -- a shell running windows applications. Some of these may be compiled with a Linux compatibility library (Cygwin). But they don't have to be. This provides a less "Linux-like" experience but may be a good compromise if all you want are some Linux command line tools and don't need to install full-blown Linux executables.
Definition of PATH for both "environments" is different. Check that node's dir shows up on Git bash's and not in WSL Bash. Run this on both environments:
echo $PATH

Running npm script on windows starting with a period

I have a package.json file with the following script defined:
"scripts": {
"test": "./node_modules/selenium-cucumber-js/index.js"
}
When I run npm test on linux or mac this script runs as expected. On Windows however I get an error:
/node_modules/selenium-cucumber-js/index.js
'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Test failed. See above for more details.
However if I run the command ./node_modules/selenium-cucumber-js/index.js directly from a cmd prompt it works correctly. The same issue also occurs if I try to run any other script through npm that starts with a ".". I haven't been able to find any other thread talking about this as an issue.
I am running npm versions 5.6.0 on Windows 10 Home.
Does anyone know how I can get this working?
Since npm 5.1
npm config set script-shell "C:\\Program Files (x86)\\git\\bin\\bash.exe"
or (64bit installation)
npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe"
Note that you need to have git for windows installed.
You can revert it by running:
npm config delete script-shell
Everything defined under scripts gets executed in the default system shell and on Windows ./node_modules/selenium-cucumber-js/index.js is definitely not a valid command (or rather a path). It just happens that the same file has a +x argument and a shebang pointing to a Node.js (or another JS interpreter) binary so that it gets executed on Linux without intervention.
I'm quite certain you'll get the same error if you were to execute the same command in the default Windows shell (cmd.exe) but you may get away with it in some ports/emulations of *nix shells (i.e. Cygwin, MSYS, bash.exe etc.) which may give you a false sense of everything working correctly outside of the npm chain.
If you want to make sure your script gets executed by Node.js while using relative paths and keeping cross-platform compatibility, call it explicitly as:
"scripts": {
"test": "node ./node_modules/selenium-cucumber-js/index.js"
}
This will also take care of things like not having a proper x flag or shebang in the script you're executing and since Node.js is perfectly comfortable with using *nix paths on Windows it won't complain either.
Whenever you write a shell script, you need to specify which shell it is written for. For inline package.json scripts, you should do this in an .npmrc alongside your package.json, like this:
script-shell = bash
If you don't specify a shell, npm is free to pick any old shell. On Windows, it picks cmd.exe, which is almost never what you want.
(Note: I don't recommend using npm config set for this. It sets local user configuration. The correct shell should be stored in version control alongside your scripts.)

Command not found in bas

I'm so sorry because I know this is a dumb question, but I've been trying to figure this out for about 2 hours and I can't figure it out. I've created a bash file that uses some other programs (tcpdump, tshark). The bash runs as it should but on every line that I use tshark, tcpdump, etc. it says "command not found".
I'm using Cygwin on my Windows 7 VM. All of the files are in the same folder and I I've tried adding the locations of the other programs to the PATH variable. I tried commands such as export PATH=$PATH:filelocation but when I do $PATH those results aren't showing. How can I get these commands to be recognized?
Thank you.
current errors
Cygwin is not a Linux distro, therefore, you don't have all the functionality like you would if you had a Linux installation.
You could try one of the following.
1) Use Virtualbox to make a VM of some Linux distro and use bash there. You could use Ubuntu server, which has no GUI.
2) Use this site to find packages that will add functionality to Cygwin.
3)Upgrade to Windows 10 and have a native (sort of) bash to use.

How to open gnuplot from mobaxterm?

I'm not sure how to open Gnuplot from MobaXterm. I've been trying many different commands but they all don't work. When I try, I get the same error.
-bash: gnuplot: command not found
I'm curious if I downloaded Gnuplot to the wrong part of the computer or if I'm not getting the command right? I'm trying to write a program in shell script that opens Gnuplot on it's own and plots data through the shell script.
Any help is appreciated!
mobaxterm is not a linux server. So you cant install packages into it normally.
you must download plugins if you can find the plugin you are looking for
check their list here
http://mobaxterm.mobatek.net/plugins.html
and it seems gnuplot is not there .
in this case your easiest solution is to download cygwin and add gnuplot on it which is possible
other option is to run small virtual machine so you can test on it
in all cases mobaxterm is not real linux enviroment so to be sure your shel do work on normal linux machines you will need to develop and test on real linux
You can install the winbuild of gnuplot and add the path to the bin directory, with gnuplot.exe in it, to mobaxterm's PATH (probably set it in .initrc or .bashrc, whichever you prefer).
MobaXterm is a standalone program which 'emulates' a Linux terminal but has no idea about your frame system (e.g. your Windows and your programs). So if you type 'gnuplot' Moba has no idea what is this. You have to
change the current directory to where is wgnuplot.exe e.g.:
cd /drives/c/Program\ Files/gnuplot-4/bin
./wgnuplot.exe
or run directly it:
/drives/c/Program\ Files/gnuplot-4/bin/wgnuplot.exe
or change your $PATH:
PATH=$PATH:/drives/c/Program\ Files/gnuplot-4/bin
wgnuplot.exe
or create a script named 'gnuplot' which runs wgnuplot.exe
#File name: 'gnuplot'
#!/bin/sh
/drives/c/Program\ Files/gnuplot-4/bin/wgnuplot.exe
and place it into some $PATH directory:
`/bin` or `/usr/bin` or `/drives/c/WINDOWS` or `/drives/c/WINDOWS/system32`
or... :)
The simplest way I found out is to use the Moba Package Manager to install the win version of gnuplot.
Open MobaXterm and type MobApt. An GUI will open up and you can type in "gnuplot" in the filter field.
Just select and install the package, MobApt will take care of any dependencies for you.

Unable to create vagrant file (homestead.yaml) on windows

I'm gonna to use vagrant on my windows desktop to develop Laravel project. I have followed all the steps to do that. But it has been failed to create homestead.yaml using bash init.sh command.
Below is the error :
Fakhreddin#Lenovo-PC3 /cygdrive/d/laravel-vagrant/homestead
$ bash init.sh
cp: unwritable ‘/home/Fakhreddin/.homestead/Homestead.yaml’ (mode 0500, r-x------); try anyway?
I'm using Cygwin for simulating Unix terminal in the Windows.
(Copy of the comment I wrote above)
Never used Cygwin in my life, but what I would try is to run it as Administrator and re-try.
Otherwise, you may want to consider changing console client. For example, if you install Git, you should be able to use Unix commands via standard Windows console.
I would seriously point the fault at Cygwin, or its settings. I am a member of a team in which all of us run Homestead on Windows 7, with no problems at all. The difference is, we use native Windows command line.

Resources