This repository is a collection of Windows batchfiles, primarily to practice batchfile syntax and test the various batch functionality available.
The targeted audience of this repository primarily is developers just getting started writing batchfiles. For developers only needing to accomplish simple tasks in the command line window, the common workflow wiki page should be enough to get started.
This repository contains files that test out:
- most in-built batchfile commands
- variables
- function definitions
- with local and global scopes
- loops
- for loops
- while loops
- conditional logic
- various other functionality, e.g.
- user input
- string manipulation
- redirection (piping)
A more detailed description of most concepts touched on here can be found in the wiki.
- batch_training.bat
- Showcases a number of common built-in batchfile commands, such as echo, cd, dir and md. Note that this file is not meant to be run and only is a batch file to contain proper syntax highlighting. It exits early in case it is run.
- function.bat
- Showcases functions with local and global scope.
- function2.bat
- Showcases a function with mixed scope.
- function3.bat
- Showcases a function with local scope and a return value passed back to global scope, using the syntax:
setlocal
set /a var_from_local_scope=1
endlocal & set var=%var_from_local_scope%
- for_test.bat
- Showcases the for keyword, with its various switches ( /l, /d, /r, /f ).
- for_with_label.bat
- Showcases a for loop using goto labels.
- while_test.bat
- Showcases a while loop using goto labels.
This section contains various other scripts, including conditional statements, user input, file redirection (piping), and other functionality.
- choice_test.bat
- conditionals.bat
- delayedexpansion.bat
- delayedexpansion_without_setlocal.bat
- input_test.bat
- random_number.bat
- redirection.bat
- script_with_args.bat
- string_substitution.bat
- substring.bat
To get a copy of this repository, simply open up git bash in an empty folder and use the command:
$ git clone https://github.com/rbaltrusch/batch
Any contributions, such as additional features, bugfixes, or documentation are much appreciated. Contribution guidelines are specified in CONTRIBUTING.md.
This repository is open-source software available under the MIT license
Please raise an issue for code changes. To reach out, please send an email to richard@baltrusch.net.