shell script looses access after calling maven - shell

Here's what I am trying to do with my windows batch file script
cd C:\git\foo
call mvn clean install
cp target\foo-bar.war C:\jboss\standalone\deployments\foo-bar.war
call C:\jboss\bin\standalone.bat
After the call to mvn, the execution stops. How do I make the other two lines execute as well?
Note: I have gow installed and I use bash commands such as cp, rm, cd etc...
It works when I uninstall gow. But then I have to change all my commands to windows shell commands. Is there any chance to make it work with gow installed?

Related

Bash script which works on both Windows and Mac

Wirting a simple bash script
#!/bin/bash
wget -q https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz
tar -zxf helm-v${HELM_VERSION}-linux-amd64.tar.gz
mv ./linux-amd64/helm ${BIN_PATH}/helm
rm -rf linux-amd64/ helm-v${HELM_VERSION}-linux-amd64.tar.gz
chmod +x ${BIN_PATH}/helm
But I have to remove the end-of-line (CRLF & LF) every time I switch from Windows to Mac or vice-versa.
At the package doc2unix (https://formulae.brew.sh/formula/dos2unix) to handle these at the moment.
Is there any best practice how to handle this, so scripts can work seamlessly without any changes?
There are a few options,
If you are using a Git repository or a version control system, where a setting is available to automatically change line endings, from LF to CRLF. When a user downloads a script. Most users have a version control system, and prefer this method, if it is just line endings you are dealing with, when it comes to running the same script.
Have two versions of a file within two folders, which is one for Windows and one for Linux, or in your script write some code to detect what the OS is and then run your code which would work with the OS.
Software which can convert a file for executing from Windows to Linux, you are using one already called doc2unix

how to run textcleaner imagemagick script from git bash

I installed Git Bash on Windows system. Now I want to run textcleaner Imagemagick script from it. Which package do I need to download to run textcleaner script and how to set the path for that script. Please help.
Steps to make textcleaner work:
open git bash.
navigate to the directory of your wish. This way you avoid writing long paths to your images and stuff (see also https://stackoverflow.com/a/22509024/8340945)
insert the downloaded script in this directory.
(as in this answer)
chmod +x textcleaner
./textcleaner ... arguments ..

trying to write a script to run a command in a deep directory on entry to ssh

So I'm trying to write a script that will let me run a command to initialize some things. To be more specific, let's say I start in my home directory but to run this command I want I must be in a directory three folders deep into the home directory.
My script looks generically like this.
#!/bin/sh
cd home/path/to/final/directory/
command
Now usually, when I cd to this directory I can run the command on the command line and everything works fine.
When I tried to use a script to do it, the command line throws an error saying that that command isn't recognized like the computer doesn't know where to look.
The temporary fix I used was making a symbolic link to the directory I wanted but I was hoping someone could help me so that when I ssh to this node this script can be run immediately so I will not have to go into the deep directory, run the command and leave again.
Try defining full paths, for example:
#!/bin/sh
cd $HOME/path/to/final/directory && /path/to/your/command
In this case, it will try to cd into your defined directory but if it can't find the dir it will not run the command, this because of the &&
To test before running the command you could do a ls, for example:
cd $HOME/path/to/final/directory && ls

Unable to execute githooks on some windows machines

I had compiled a golang code and got a binary out of it. This binary was the pre-commit git hook.
However this git hook does work on some windows machines and it does not work on some windows machines. I use GitBash for running git commands.
I don't know what the issue might be. I did run it on Windows 10 and it worked on one of the machines and didn't work on another one.
Please make sure your script is executable. To check whether the file is executable, run this in your terminal
ls -l /path/of/file
If you find it as non executable, Use this command for making it as an executable.
chmod +x /path/of/file
If you don't know what is ls -l. Please go through here. https://askubuntu.com/a/528433

how to run script with simple command

I have project structure like this
project
|app
|script
inside script folder, there are files such as 'run'
run file content:
#!/bin/bash
npm start
I want to run the file 'run' while I'm at the root of my project by typing only command 'run'. How would you do this?
This is sh file. In order to execute sh file on linux this file has to be executable.
Make sure this file has X permission.
If there is no x permission on file simply execute the command
chmod +x run.sh
Then execute the file by typing
./run.sh
For windows you need to create .bat file.
I'm not quite sure what you want but assuming you need a way to execute a file from node.js, you can use child_process module and child_process.exec method to start any executable.
Assuming the run file in the script directory is executable (if not, run chmod +x script/run), it can be executed by running ./script/run.
If you want to avoid having to type the name of the directory (script), you could append the script directory to your PATH environment variable. If you’re running a POSIX compatible shell (not csh or tcsh), this can be done using:
export PATH="$PATH:/path/to/project/script"
This will allow you to run any executable command in the script directory without having to specify the name of the directory, e.g., run.
NB: be sure that there aren’t common command names in the script directory as these commands can be run from any directory (including outside the project directory) after it has been added to the PATH. That’s also why I suggest adding it to the end of the PATH (so it’s the last directory that’s searched for executable commands).

Resources