Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use logical AND (&&) in Powershell?

In terminal I used to run two commands at once using '&&' operator. For example if I want to compile and run C source code I only need to write: gcc code.c && ./a.out. But unfortunately it doesn't work in Powershell. How can I do this? And I'm sorry I couldn't find any easier method to do this. Therefore, I had to post it here! TIA!

like image 728
Afif Al Mamun Avatar asked Oct 30 '25 01:10

Afif Al Mamun


1 Answers

After searching here and there I found out '&&' doesn't work in PS. There is '-and' command in lieu of '&&'. But in my case I actually wanted to execute two command at once and it didn't work. I found a way to do this. A simple semicolon could do the work. For example: If I want to compile and run a C++ code, I just need to write g++ /directory/code.cpp; ./a.exe. But if someone uses this they should be aware of that the second command will work even though the first one doesn't execute due to any error unlike the '&&' operator!

like image 195
Afif Al Mamun Avatar answered Nov 01 '25 16:11

Afif Al Mamun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!