Git Bash Open Command Windows
Asked Answered
B

10

18

I'm extremely new to the command line and just programming in general. I use windows, and I'm doing prep work for viking code school. In one of the lessons it asks us to use the 'open' command in Git Bash (we were to download Git Bash if we weren't on Linux or Mac) which will not work for me. When I type it, I get the error "bash: open: command not found", how can I fix this or work around it? Thank you

Bugbee answered 26/9, 2015 at 4:53 Comment(3)
Use the open command for what?Rhomboid
anything, that's the point. see below for an example of opening .txt - but in Linux you could open anything that way, I think...Tweeze
Use '"start 'filename'.txt" to open the file in windows Gitbash...It worksAlenaalene
C
18

No you can't use open on windows. I think the closest to open in windows will be explorer, which will open the file using default associated windows programs.

Caroncarotene answered 14/12, 2016 at 19:50 Comment(1)
Will also urls properly with the standard browser!Cypress
S
12

open isn't a shell command or a program name, it is a system call.

On Unix, Unix-like and other POSIX-compliant operating systems, popular system calls are open, read, write, close, wait, exec, fork, exit, and kill.

Git for Windows is based on mingw64, and open() is not a system call on Windows. Simply calls an editor or a bash command to open the file.

cat file.txt
more file.txt
/path/to/editor.exe file.txt # like sublimeText.exe

Julix adds an example illustrating a Windows path:

/c/WINDOWS/system32/notepad.exe file.txt(<- change that to your file)
Stroup answered 26/9, 2015 at 10:11 Comment(7)
So is there something in Git Bash I can use to open files?Bugbee
@BrandenKennedy simply call any windows program you want from your bash session: /c/WINDOWS/system32/nnotepad.exe myfileStroup
doesn't that deserve an upvote then? possibly accepted answer?Tweeze
This answer isn't really on-target @Julix, and there are other answers that have more useful content. The OP is looking for a call equivalent to the XDG Desktop command xdg-open, not the system call. This command will run the client software configured in the OS to use for the targeted file extension. Hence xdg-open file.pdf is for the OP start file.pdf, and will start Acrobat reader, or whatever is appropriate, not just Notepad.Catechist
@Catechist thanks for expanding on that! That's a good point... when a user clicks on a file in windows something "like" a dynamic "open" must be going on to look up "for this type of file, what am I to do?" - wonder why we can't run that in windows commandline.Tweeze
@Julix, better not start wondering "why can't I do that in Windows that you can do in Linux / bash" - that's a journey that will never end.Catechist
I don't mean it in a judgemental way, I think there likely would be an interesting historical answer to the question, maybe one of permission or company politics or feature pressure / timing / convention / prioritization. Would be neat to know which, but out of scope for this question for sure :DTweeze
U
12

I found two kinds of command lines would work same as open in Mac.

start filename
explorer filename
Unproductive answered 30/1, 2019 at 16:58 Comment(0)
D
10

I'm also a complete beginner, but it seems that the command you want is start (at least when applied to a program or program-file-pair).

Dragging answered 12/5, 2018 at 9:6 Comment(0)
G
3

If you are using GIT BASH on Windows PC - then to open a text file, type start notepad.txt

where start will 'open' your file, make sure to add the file extension also.

You can use start for opening images too.

start favicon.png or start readme.md
for example.

(If you want to add text to that .txt file using BASH then type, echo "type something with quotations" >> yourtextfile.txt)

Gabrila answered 28/8, 2020 at 14:37 Comment(0)
C
3

start command works for me on Windows machine as a replacement for the open command.

Craggy answered 16/12, 2020 at 21:36 Comment(1)
Finally thought of ... hey Mike why not GOOGLE the issue and see if you can find it -- so did that with "bash: open: command not found". Exactly that and only that. I'll be damned ... here's the answer! :)Laundress
C
2

For Git Bash on Windows, type the .exe name of your editor, for example, Visual Studio Code exe is Code.exe followed by space and dot. So you write Code ., and it will open all files with your editor.

Circumgyration answered 12/8, 2018 at 22:32 Comment(0)
Q
0

look commands are little different in unix terminal and windows command prompt.. solution would be 1) Download git from https://git-scm.com/downloads this will convert your linux command to windows command 2) What is the command ..?? post it as well .. may be we can help

Quadriceps answered 26/9, 2015 at 5:9 Comment(2)
I did download Git, that's where the problem lies. as an example the command '$ open test.txt' should open 'test.txt' but it says "bash: open: command not found" in Git BashBugbee
make sure you are not adding $ before the command and not caged b/w single or double quotes secondly you should be in the same directory for ex: my "test.txt" is in abc folder and your termnal is pointing on user directory or c drive use cd path/OfYour/Folder/whereThe/fileIs/and that is /abcQuadriceps
S
0

"open" cannot be used on windows. The closest to open in windows will be the "explorer" (to open the default explorer) or "explorer ." (to open the current directly).

Samantha answered 11/10, 2019 at 5:23 Comment(1)
yes, it was copied, the original one is not with full description, cannot understand by newbies.Samantha
P
0

On Windows, to open a file called filename.txt on Git Bash terminal, simply run the line below:

code filename.txt

Poplar answered 22/7, 2024 at 13:19 Comment(1)
How is it different from @Palvin's answer? Could you edit your answer to be unique?Nally

© 2022 - 2025 — McMap. All rights reserved.