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 Read Environment Variables with Python dotenv S shubhambhugra234 Follow Improve Article Tags : Linux-Unix Batch-script Similar Reads Docker Run with Environment Variables Containerization has significantly advanced software development by packaging applications and their dependencies together and containerizing them to ensure consistency across multiple environments. Environment variables are one of the most important features of containerization as they make it poss 7 min read Bash Script - Working of Bash Variables A Bash script is a plain text file. This file contains different commands for step-by-step execution. These commands can be written directly into the command line but from a reusability perceptive it is useful to store all of the inter-related commands for a specific task in a single file. We can us 7 min read Read Environment Variables with Python dotenv Environment variables play a crucial role in the configuration and operation of software applications. They provide a mechanism to store configuration settings that can be used by applications to function properly. This separation of configuration from code allows for more secure and flexible softwa 4 min read Batch Script - Empty String In this article, we are going to create an Empty String using Batch Script. Batch Script :@echo off set str1= set str2=Hello ::using if statement we will check that str1 is empty string or not. if [%str1%]==[] echo "str1 is an empty string" if [%str2%]==[] echo "str2 is an empty string" pauseExplana 1 min read What Docker Environmental Variables ? In a Docker has entered into the developer's working culture today as a forefront system of development, testing, and deployment of applications. Docker is an important feature as it provides the users or developers with the ability to not only monitor and control the environment but to also build t 6 min read Batch Script - Create String In this article, we are going to learn how to create a String using Batch Script. Batch Script :@echo off set str=Geeks for Geeks echo %str% pauseBy using ' set ' we are getting input of any string.Ex: set str=input stringIn the next line, we are using ' echo %str% ' for printing our input string.Th 1 min read Like