Why when I create a Makefile with Notepad its saved .txt - c

When I create Makefile with Notepad it's saved with .txt How can I get rid of it ? also when I try to run the program on cygwin it says *** No targets specified and no makefile found. Stop.
P.S I am new to Makefile and Linux environments.

Windows will 'helpfully' add the .txt to any file that you create with notepad. You have several options:
(1) just rename the file from makefile.txt to makefile and things should work
(2) use the -f command line argument with make, i.e make -f makefile.txt to get make to use the correct file.
(3) seeing that you have cygwin install use emacs, or vi, or gedit as your editor.
(4) consider using notepad++ (or something similar) if you must use windows.
(5) or (and this would be my default suggestion), ditch Windows and just install Linux.
At the bottom of the save dialog box, select
Save as type: All Files (*.*)
from the drop-down menu instead of the default
Save as type: Text Document (*.txt)
Then, you could use any extension that you desire.

Make sure you select the correct file type (any) and not text file (*.txt) when saving the file (the latter adds .txt automatically if you don't do it). Btw you can also rename the file afterwards, but you have to show the file extensions in explorer to be able to change it.

Related

How to set default opener [duplicate]

How can I set TextMate as default text editor on Mac OS X?
I've tried it with
ln -s /Applications/TextMate.app/Contents/Resources/mate ~/bin/mate
export EDITOR='mate -w'
but that doesn't work.
Just right (or control) click a file of the type you want to change and:
"Get Info" -> "Open with:" -> (Select TextMate) -> "Change All"
The method through Finder is not practical. If you're a developer, your files likely include .profile, .gitconfig, .bashrc, .bash_profile, .htdocs, etc.
The best way to do this is in Bash (for Sublime Text 3):
defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.sublimetext.3;}'
For other text editors, I assume you can replace 'com.sublimetext.3' with the proper string. You could probably Google for your text editor's name + "LSHandlerContentType=public.plain-text" to figure out what your app's string would be.
For me, this changed the defaults for both Finder, and
$ open ~/.bashrc
Have you modified your shell PATH environment variable to include ~/bin? That directory is usually not included in PATH by default on OS X. It might be simpler to create the symlink in /usr/local/bin which is usually included in PATH. Try:
echo $PATH
This worked for me on OS X v10.11 (El Capitan):
defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add \
'{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.macromates.textmate.preview;}'
For TextMate 2:
defaults write com.apple.LaunchServices LSHandlers -array-add '{LSHandlerContentType=public.plain-text;LSHandlerRoleAll=com.macromates.TextMate;}'
And you need to restart after that.
To change the default text editor across the board, use the aforementioned method (i.e., "Get Info" → "Open with:" → (editor of choice) → "Change All") on .txt files. Then it will be used as the default editor for any text-based file that doesn't yet have an application preference for its extension.
For instance, if you use the terminal, the command open -t will use your preferred text editor, which is whatever application is associated with .txt files. By default this is (you guessed it) TextEdit, unless you explicitly specify otherwise.
I found Replace Text Edit as the default text editor on apple.stackexchange which works really well.
For developer-type files like .gitignore, use the last option provided:
duti -s com.macromates.TextMate public.data all
Substitute your editor's CFBundleIdentifier as needed. To find it, locate the application file, right-click and choose Show Package Contents, then open Info.plist in the Contents folder. CFBundleIdentifier should be near the top...
This work on Catalina. I'll update my answer if/when I update my OS.

How to run a exe without the extension using batch

I am making a program that optimises a PC and I have made some exe's I need a bat file that can run them even if they had an extension like "abc". I cant have them with the exe extention because if they were executed not in order it could be fatal
EDIT: does any one know how I could do the same but with a reg file with a "abc" extention as well. Thanks.
you dont need to change the registry to run an file with different extension.YOu just need to add the extension to %PATHEXT% :
set "pathext=%pathext%;.exe1"
call sample.exe1
to make a an .abc file to act as .reg try this:
assoc .abc=regfile

Delete a file named "NUL" on Windows

I ran a program on Windows 7 that was compiled under Cygwin and passed "NUL" as an output file name. Instead of suppressing output it actually created a file named "NUL" in the current directory. (Apparently it expects "/dev/null", even on Windows.) Now I'm stuck with this "NUL" file that I cannot delete!
I've already tried:
Windows Explorer - error: "Invalid MS-DOS function" (yes, that is seriously what it says!)
Command prompt using "del NUL" - error: "The filename, directory name, or volume
label syntax is incorrect."
Deleting the entire directory - same deal as just deleting the file
remove() in a C program - also fails
How can I get rid of these NUL files (I have several by now), short of installing the full Cygwin environment and compiling a C program under Cygwin to do it?
Open a command prompt and use these commands to first rename and then delete the NUL file:
C:\> rename \\.\C:\..\NUL. deletefile.txt
C:\> del deletefile.txt
Using the \\.\ prefix tells the high-level file I/O functions to pass the filename unparsed to the device driver - this way you can access otherwise invalid names.
Read this article about valid file / path names in Windows and the various reserved names.
If you have Git for Windows Installed (v2.18) do the following
Open the directory containing the files you want to remove
Left Click and select Git Bash Here
Type rm nul.json at the command prompt and hit ENTER, the file now should be removed.
NOTE: These screenshots show the removal of file nul.topo.json which is another file that I could not removed with a simple delete.
If you have git on windows, just right click on the folder containing the nul file -> go to gitbash here -> and type "rm nul" or "rm nul.json" depending upon the file type.
I had a similar issue. It was probably caused by Cygwin as well (since I use this regularly), but I've since forgotten exactly how the file was created.
I also had trouble deleting it. I followed the advice of some other posts and tried booting into safe mode to delete the file, though this did nothing. The tip from +xxbbcc didn't work for me either.
However, I was able to delete the file using the Cygwin terminal! Cygwin createth and Cygwin destroyeth.
To remove a nul file situated here:
C:\unix\cygwin\dev\nul
I simply use (tested only on Windows 10) :
Del \?\C:\unix\cygwin\dev\NUL
I solved this in a slightly different way.
I thought I would add this here because it is high in the google results and I had a similar issue for a folder named NUL.
I tried rmdir\\?\C:\My\Path\NUL and rmdir\\.\C:\My\Path\NUL without any success and also tried several commands using bash from my SourceTree installation. No joy.
In the end I used DIR /X /A from cmd to list the short names in the parent directory. This showed me NUL~1 for my NUL folder and identified the crux of the problem.
This was then used in the standard command rmdir /s NUL~1 and finally resolved the issue.
I was having this same issue.
If you have WSL2 installed just go to that directory and run:
rm -f nul
In my case the file was lowercase. You should be good.
Try writing a short C program that calls the Windows API to delete that file.
http://msdn.microsoft.com/en-us/library/aa363915%28v=vs.85%29.aspx
If that doesn't work, try opening a handle to the file with CreateFile() with FILE_FLAG_DELETE_ON_CLOSE, and then close the handle.

Running a shell script through Cygwin on Windows

I have a bunch of shell scripts that used to run on a Linux machine. Now, we've switched over to Windows, and I need to run these scripts there. I have Cygwin installed, but is there a way to make the script run using Cygwin, but the call is made from Windows batch?
Sure. On my (pretty vanilla) Cygwin setup, bash is in c:\cygwin\bin so I can run a bash script (say testit.sh) from a Windows batch file using a command like:
C:\cygwin\bin\bash testit.sh
... which can be included in a .bat file as easily as it can be typed at the command line, and with the same effect.
One more thing - if You edited the shell script in some Windows text editor, which produces the \r\n line-endings, cygwin's bash wouldn't accept those \r. Just run dos2unix testit.sh before executing the script:
C:\cygwin\bin\dos2unix testit.sh
C:\cygwin\bin\bash testit.sh
If you have access to the Notepad++ editor on Windows there is a feature that allows you to easily get around this problem:
Open the file that's giving the error in Notepad++.
Go under the "Edit" Menu and choose "EOL Conversion"
There is an option there for "UNIX/OSX Format." Choose that option.
Re-save the file.
I did this and it solved my problems.
Hope this helps!
Read more at http://danieladeniji.wordpress.com/2013/03/07/microsoft-windows-cygwin-error-r-command-not-found/
Just wanted to add that you can do this to apply dos2unix fix for all files under a directory, as it saved me heaps of time when we had to 'fix' a bunch of our scripts.
find . -type f -exec dos2unix.exe {} \;
I'd do it as a comment to Roman's answer, but I don't have access to commenting yet.
The existing answers all seem to run this script in a DOS console window.
This may be acceptable, but for example means that colour codes (changing text colour) don't work but instead get printed out as they are:
there is no item "[032mGroovy[0m"
I found this solution some time ago, so I'm not sure whether mintty.exe is a standard Cygwin utility or whether you have to run the setup program to get it, but I run like this:
D:\apps\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico bash.exe .\myShellScript.sh
... this causes the script to run in a Cygwin BASH console instead of a Windows DOS console.
If you don't mind always including .sh on the script file name, then you can keep the same script for Cygwin and Unix (Macbook).
To illustrate:
1. Always include .sh to your script file name, e.g., test1.sh
2. test1.sh looks like the following as an example:
#!/bin/bash
echo '$0 = ' $0
echo '$1 = ' $1
filepath=$1
3. On Windows with Cygwin, you type "test1.sh" to run
4. On a Unix, you also type "test1.sh" to run
Note: On Windows, you need to use the file explorer to do following once:
1. Open the file explorer
2. Right-click on a file with .sh extension, like test1.sh
3. Open with... -> Select sh.exe
After this, your Windows 10 remembers to execute all .sh files with sh.exe.
Note: Using this method, you do not need to prepend your script file name with bash to run

batch rename files with different file extensions to 1 extension

I'm recently new to batch scripting. I need to rename a few thousand files, each one having a different file extension to a single common extension. The files come off a machine like so:
1.2.840.113619.2.131.3171610912.1353091118.893703
which windows tells me is a type "893703" file because of the fullstop(.) position.
So I need to turn this example:
1.2.840.113619.2.131.3171610912.1353091118.893703
1.2.840.113619.2.131.3171610912.1353091118.907596
1.2.840.113619.2.131.3171610912.1353091118.920723
1.2.840.113619.2.131.3171610912.1353091118.932988
1.2.840.113619.2.131.3171610912.1353091118.945443
into this
1.2.840.113619.2.131.3171610912.1353091118.893703.IMA
1.2.840.113619.2.131.3171610912.1353091118.907596.IMA
1.2.840.113619.2.131.3171610912.1353091118.920723.IMA
1.2.840.113619.2.131.3171610912.1353091118.932988.IMA
1.2.840.113619.2.131.3171610912.1353091118.945443.IMA
I can edit the text string before the extension, and change a series of the same extension, but I'm not sure how to deal with files of different extensions.
I'm using Windows 7.
Run the following on the command line:
ren *.* *.*.IMA

Resources