Batch Script - Working with Environment Variables Last Updated : 01 Aug, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Environment Variables refer to the variables which are globally declared and can be accessed by the processor under the management of OS like Windows, Mac, and Linux. In starting they were meant to store the path locations but now they also work with Batch Script. The data of batch programs like input from CMD prompt, text files, log files, etc are stored under this. The user can easily change the search path using a batch file so that the applications can be run efficiently. If a variable is undefined and a batch file is scanned, some unwanted execution can occur. An example is given below:- @echo off set /p result = Want to say Hello ? (Y/N) ? if /i "%result:~,1%" EQU "Y" echo Hello Ji! if /i "%result:~,1% EQU "N" echo Bye Bye pause "Y" input from the user will lead to print hello as mentioned above."N" input from the user will lead to print bye-bye. Benefits of Environment VariablesEfficient Execution Performance: It boosts the performance of the batch script so the commands which are executing run in less time and space complexities. Make script application secure: Credential information got highly secured after using environment variablesReduce Execution mistakes: Runtime execution errors reduces to a large extent after developing environment variables as it configures them properly.Environment expressions are as follows:%name:~n% - It skips the first "n" letters and returns the remaining.%name:~n,m% - It skips "n" letters and returns the next "m"%name:,m% - Leftmost "m" number of letters.%name:~-m% - Rightmost "m" number of letters.Output Examples of the above expressions: 1.) ECHO %var% : 2.) ECHO %var:~2,3% : 3.) ECHO %var:~-3% : 4.) ECHO %var:~,3% : 5.) ECHO %var:~2%: Comment More infoAdvertise with us Next Article Batch Script - Working with Environment Variables S shubhambhugra234 Follow Improve Article Tags : Linux-Unix Batch-script Similar Reads Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact 12 min read 3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power 13 min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac 13 min read Linux Commands Cheat Sheet Linux, often associated with being a complex operating system primarily used by developers, may not necessarily fit that description entirely. While it can initially appear challenging for beginners, once you immerse yourself in the Linux world, you may find it difficult to return to your previous W 13 min read Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca 7 min read Linux/Unix Tutorial Linux is one of the most widely used open-source operating systems. It's fast, secure, stable, and powers everything from smartphones and servers to cloud platforms and IoT devices. Linux is especially popular among developers, system administrators, and DevOps professionals.Linux is:A Unix-like OS 10 min read CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi 6 min read Like