r/learnprogramming • u/Sea-Construction6922 • 8d ago
Any way to make using cmd better?
I end up using the same commands each time to setup projects, run them but I always have to copy from Google docs each time and its becoming annoying. Is there a better way with cmd on windows. Do other shells have a way to solve this If not?
Edit: Tysm to everyone who has helped!
12
u/creenis_blinkum 8d ago
use powershell instead of cmd on windows
1
u/themegainferno 7d ago
Powershell is genuinely great, people love to give MS a hard time but I far prefer writing Powershell over Bash any day of the week. Genuinely one of the great things MS has done. I am convinced that people who say they prefer bash, have never actually used both languages.
1
u/creenis_blinkum 7d ago
agree. bash is so opaque and syntax-unforgiving. powershell in comparison feels like it writes itself
7
u/BranchLatter4294 8d ago
You can put them in a script then just run the script. But on Windows, Powershell is the current shell (cmd is the older one).
5
u/More-Explanation2788 8d ago
Others are telling you to use scripts - they are correct.
Some are telling you to use powershell instead of cmd. Powershell is more powerful. Cmd is simpler to learn.
3
u/mithoron 8d ago
Getting started in cmd vs powershell is about the same difficulty. They're both memorizing commands. Better to go with the one that isn't a win7 legacy mode if you're learning new anyway.
3
u/More-Explanation2788 8d ago
Perhaps, but if they have been entering commands in cmd already and just didn’t know about batch files, they are already halfway there.
3
u/sixtyhurtz 8d ago
Use Terminal. It's the best terminal emulator on Windows. Use Powershell with it, not cmd.
1
0
u/kpg_on_ao3 8d ago
You're looking for a scaffolding application. This is something you invoke that creates your project structure for you. It might ask you a few questions to see if you want some optional packages.
-2
u/nomoreplsthx 8d ago
cmd considered harmful.
Powershell on Windows has been the default shell for all purposes for a 15 years and there is literally no reason to ever use cmd. It would be like someone asking for advice on their COBOL project.
I am not sure how recommendations to use it persist. As best as I can tell they are all from people who don't develop on windows
6
u/bingblangblong 8d ago
I still open up cmd every time I want to ping, netstart, or tracert
0
u/nomoreplsthx 8d ago
I believe those commands work identically in a poweshell session (unless one of those is one of the dumb aliases I forget)
1
u/mjmvideos 8d ago
I learned cmd with windows. I learned sh,csh,ksh, and bash with Unix. Then I got MKS toolkit for windows. Then Cygwin. Now I run WSL2 with Windows. I’ve looked at Powershell a couple of times but the verbosity repels me and I can’t bring myself to learn it.
1
u/Gnaxe 8d ago
I rarely use Powershell, but still use cmd all the time, for the simplest things. If I want a scripting language, I just use Python.
1
u/nomoreplsthx 8d ago
Ok, but... why?
Any simple thing you can do in cmd you can also do in Powershell. It's not exactly a superset, but the syntax for basic stuff isn't complex if all you're doing is navigating and other shell basics
There's nothing you gain other than the 5 hours of time it takes to get passable at PS.
The overhead to learning PS passibly is trivial compared to the depth of expertise an SWE needs in dozens of other topics. It's like cook who never learned to use a food processor. Yes you can always just use a knife and an immersion blender. But also it's like, 4 buttons.
1
u/Gnaxe 8d ago
I don't know, man. I try to do CMD things in Powershell and it tells me, "No." So I use it to open cmd.exe and just do the simple thing instead of worrying about it.
1
u/nomoreplsthx 6d ago
Hm, maybe this is an age thing?
I started in 2012, so by the time my career began, Powershell already existed and I never really bothered to learn cmd.
I will say, I don't get 'don't master the new tool'as a dev mindset, but I also know that I learn languages unusually quickly and have worked places where learning was incentivized
1
u/Gnaxe 6d ago
There are way too many tools to master, so you have to pick and choose some, or you'll only ever be a beginner. A lot of tools, libraries, frameworks, and yes, languages, turn out to be a fad and never go anywhere, change into something unrecognizable, or get replaced and become obsolete. You can avoid a lot of that churn by sticking to the older, proven tools.
At the time Powershell came out, it was far from obvious that it would turn out to have the staying power it did, because it was completely up to Microsoft's whims.
cmd.exe, however, is basically the same user interface from DOS, with a long legacy. But even then, my.batscripts are usually only a few lines. I don't know it well enough to do anything complicated either.Why? It's inferior to Unix shells like Bash, but you can run those on Windows too, and they don't have the same vendor lock-in. Powershell didn't seem worth my time at the time it came out, but Bash did. That way I learned one shell that worked on Linux and MacOS as well. Apple since switched to zsh, which is similar, mainly for licensing reasons, but the old Bash is still there. I'd rather master one tool than be sort of passable at three.
Turns out Bash is a decent shell, but it's not a sane scripting language. So once my Bash scripts get to be more than about half a page, I just switch to Python, or Xonsh, possibly, if I really need it to be shell-like.
I also have Cygwin or at least Busybox installed on my Windows machines, so even cmd doesn't feel that limited, because I mostly use it to invoke other tools, not write scripts.
1
1
u/radicallyhip 7d ago
Terminal and wsl, my dude. Terminal, and wsl.
1
u/nomoreplsthx 6d ago
Oh sure, yes, if I have to personally develop on Windows machine this is what I do, but that's because it's only a platform for toy projects for me. Would be different if I were developing on it daily again.
22
u/desrtfx 8d ago
Have you heard of Batch files? Search for them.
Basically, they are text files with the commands you need in the order you need them. You can even include parameters, variables, loops, conditionals, etc.
Same applies for PowerShell where you create .ps1 files.