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
Related
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
I have a pretty basic problem here, that has happened so haphazardly to me that up until now, I've just ignored it. I downloaded tomcat web server and "Murach's Java Servlets and JSP" book is telling me to navigate to the tomcat/bin directory and start the server my typing in Terminal
$ startup
However, I get the error
-bash: startup: command not found
The relevant files in this directory are startup.sh and startup.bat. Typing both of these returns the same error message
So my questions are, what are .bat and sh files, and how do I run these files? I've read several tutorials for different languages and software programs, and some times when the tutorial says execute a bunch of files in the command line, I get a "command not found" error. Sometimes it works, sometimes it doesn't. This is perplexing to me, so what are some common solutions to solving these sort of "command not found" Terminal problems?
The .sh is for *nix systems and .bat should be for Windows. Since your example shows a bash error and you mention Terminal, I'm assuming it's OS X you're using.
In this case you should go to the folder and type:
./startup.sh
./ just means that you should call the script located in the current directory. (Alternatively, just type the full path of the startup.sh). If it doesn't work then, check if startup.sh has execute permissions.
This is because the script is not in your $PATH. Use
./scriptname
You can also copy this to one of the folders in your $PATH or alter the $PATH variable so you can always use just the script name. Take care, however, there is a reason why your current folder is not in $PATH. It might be a security risk.
If you still have problems executing the script, you might want to check its permissions - you must have execute permissions to execute it, obviously. Use
chmod u+x scriptname
A .sh file is a Unix shell script. A .bat file is a Windows batch file.
Type bash script_name.sh or ./script_name in linux terminal. Before using ./script_name make you script executeable by sudo chmod 700 script_name and type script_name.bat in windows.
Drag-And-Drop
Easiest way for a lazy Mac user like me: Drag-and-drop the startup.sh file from the Finder to the Terminal window and press Return.
To shutdown Tomcat, do the same with shutdown.sh.
You can delete all the .bat files as they are only for a Windows PC, of no use on a Mac to other Unix computer. I delete them as it makes it easier to read that folder's listing.
File Permissions
I find that a fresh Tomcat download will not run on my Mac because of file permission restrictions throwing errors during startup. I use the BatChmod app which wraps a GUI around the equivelant Unix commands to reset file permissions.
Port-Forwarding
Unix systems protect access to ports numbered under 1024. So if you want to use port 80 with Tomcat you will need to learn how to do "port-forwarding" to forward incoming requests to port 8080 where Tomcat listens by default. To do port-forwarding, you issue commands to the packet-filtering (firewall) app built into Mac OS X (and BSD). In the old days we used ipfw. In Mac OS X 10.7 (Lion) and later Apple is moving to a newer tool, pf.
Based on IsmailS' comment the command which worked for me on OSX was:
sudo sh ./startup.sh
On windows type either startup or startup.bat
On unix type ./startup.sh
(assuming you are located in tomcat/bin directory)
Batch files can be run on Linux. This article explains how (http://www.linux.org/threads/running-windows-batch-files-on-linux.7610/).
Type in
chmod 755 scriptname.sh
In other words, give yourself permission to run the file. I'm guessing you only have r/w permission on it.
add #!bin/bash on top of the your .sh file
sudo chmod +x your .sh file
./your.sh file
these steps work~
My suggestion does not come from Terminal; however, this is a much easier way.
For .bat files, you can run them through Wine. Use this video to help you install it: https://www.youtube.com/watch?v=DkS8i_blVCA. This video will explain how to install, setup and use Wine. It is as simple as opening the .bat file in Wine itself, and it will run just as it would on Windows.
Through this, you can also run .exe files, as well .sh files.
This is much simpler than trying to work out all kinds of terminal code.
I had this problem for *.sh files in Yosemite and couldn't figure out what the correct path is for a folder on my Desktop...after some gnashing of teeth, dragged the file itself into the Terminal window; hey presto!!
I'm quite a beginner with version control so I might be doing something very wrong.
I want to be able to access a local repository both in cygwin and in TortoiseSVN (or other Windows app). The trouble is, in cygwin I have to use the
file:///cygdrive/c/... paths while TortoiseSVN needs
file:///c:/....
How can I make these two work together? Can I use some other path/protocol that both understand?
Thanks!
Easy way is to use the svnserve program that comes with Subversion. This should be in Cygwin. All you need to do is start up the svnserve and use svn:// as the protocol instead of file://.
First, you need to modify your repository. You'll have to edit two files: svnserve.conf and passed.
$ cd /cygdrive/c/.../repos_dir
$ cd conf
$ vi svnsever.conf # Change the "# password-db = passwd" line & remove the "#"
$ vi passwd # Setup the user and password entry
Next, you start the server:
$ cd .. # Back to the repository directory
$ svnserve -r $PWD -d
And, that's it.
Now, you can do your checkout this way:
$ svn co svn://localhost/dir/to/check/out
This will be the same URL in both cygwin and in Tortoise
WORD 'O WARNING
There is no guarantee that different subversion clients will produce working directories that will work with other subversion clients.
Fortunately, Tortoise and the standard Subversion command line client seem to be okay. I've been able for the last few years to switch between the Subversion command line client and ToroiseSVN. HOWEVER, you do have to make sure that they're both ether post version 1.7 clients or pre 1.7 clients. If your Cygwin client is version 1.6.7 and your Tortoise client is 1.7.5, you can't share the working directory. Use the svn version command to check your Cygwin client, and check the About Box on Tortoise.
Again, there's no guarantee that both clients can share the same working directory, so if there are problems, you are on your own.
There is a better way. Simply link the directory.
ln -s /cygdrive/c /C:
now it should work.
Credit goes to Mark Malaknov
You can read it here:
http://markmal.blogspot.com/2012/11/how-to-use-cygwin-svn-and-tortoisesvn.html
If you (re-)install TortoiseSVN and select the option to install the (Windows) command-line tools, but don't install the Cygwin/Linux version of these tools from the Cygwin installer (or remove them), then your Windows tools will still be available via Cygwin.
These should accept Windows paths as if you were invoking them from the Command Prompt (although you might have to put them in quotes to avoid the bash shell from interpreting them)
Operating system: Windows XP SP3 (Unfortunately)
I have downloaded and installed the latest version of Cygwin and Git. I also have configured my environment to include the "bin" folders for each in my system path and also set a user variable TERM=msys. I can now go into cmd and use the following command, for example:
git status
and get colored output, i.e. for status, changes to be committed are green, while untracked files and such are red. This was not the case without having set TERM=msys.
However, since I also added the Cygwin bin to my path, I can use
ls
to get a directory listing, but not with colored output. Am I correct in assuming that, since I'm only using the binaries through cmd, and not Cygwin itself, that getting colored output would have to be done differently from just configuring a BASH profile? Assuming this is possible; however it would seem to follow that if it can be done with Git, then it can also be done with the Cygwin binaries.
I'd be happy to elaborate or clarify any details. Thanks.
The basic colors should still work when you do ls --color. Since you can't use alias in cmd.exe, you can use the doskey windows utility.
doskey ls=ls --color
There are various ways you can make it so the command gets run automatically every time you start a cmd.exe shell. Here's one: http://www.tildemark.com/loading-doskey-automatically-with-cmd/
On the Windows command line and cygwin bash I can execute the following without problems:
cvs login
cvs -Q log -N -rVersion_01_00
A ruby script in the same directory contains the following:
`cvs login`;
`cvs -Q log -N -rVersion_01_00`;
When I execute the ruby script on the Windows command line I get the following error:
cvs log: warning: failed to open /cygdrive/c/Documents and Settings/za100744/.cvspass for reading: No such file or directory
If I run the script in a cygwin bash shell I get the same output I would as when I type in the commands manually.
I have no idea as to what is going wrong. The path generated by the Ruby script is wrong since it is a cygwin path but it works correctly directly on the command line. I use cvs that came as part of cygwin:
which cvs
cvs is an external : C:\cygwin\bin\cvs.exe
Ruby is the one-click installer version:
which ruby
/cygdrive/c/Ruby/bin/ruby
It seems like cvs under Ruby can not resolve /cygdrive/c to c: but works OK from the cmdline.
Perl gives me exactly the same problem.
my $str = "cvs -Q log -N -r$cvs_tag|";
open(CVS_STATUS, $str) or die "\n##ERROR##";
It looks like either CVS can't create the file, or your path is wrong. Does the file .cvspass exist? If not, this page suggests you try creating an empty .cvspass file and then run your command. e.g. do
touch ~/.cvspass
If this doesn't help, then the problem is probably path related. There are a few possibilities; $HOME not set correctly, your home dir not matching what's in \etc\passwd, etc. See this tutorial for some troubleshooting steps that should help pin down the problem.
Using a windows native compiled CVS solves the problem. It is not ideal since I have to send a cvs executable with the script for users that has cygwin CVS but its better than nothing.
We had several problems with unix-, mixed- and windows-style paths in cygwin based perl scripts and built-in tools such as rsync. E.g. rsync can't handle wind-style paths. Use the tool "cygpath.exe" to adjust them correctly. Maybe it's the cause.