BATsh
view release on metacpan or search on metacpan
positional parameters. "CALL :label" saves and restores caller's
arguments.
Batch-parameter tilde modifiers expand %0..%9 components:
%~0 dequote (strip surrounding "...")
%~f1 full absolute path of %1
%~d1 drive letter only (e.g. C:)
%~p1 directory path only (with trailing /)
%~n1 filename without extension
%~x1 extension only (e.g. .bat)
%~dp0 drive + directory (most common usage)
%~nx1 filename + extension
Redirection and Compound Commands
ECHO text > file stdout overwrite
ECHO text >> file stdout append
prog 2> err.txt stderr redirect
& cmd sequential execution
cmd1 && cmd2 run cmd2 only if cmd1 succeeded (ERRORLEVEL 0)
cmd1 || cmd2 run cmd2 only if cmd1 failed (ERRORLEVEL != 0)
The "^" character escapes the next character:
ECHO a^&b prints a&b (& not treated as compound separator)
ECHO a^^b prints a^b
ECHO text^ next line is joined (line continuation)
SH MODE
Any line whose first token contains a lowercase letter is a SH line. SH
sections are executed by BATsh::SH, which implements:
VAR=value, export VAR=value, unset VAR
echo, printf
if/then/elif/else/fi
for VAR in list; do ... done
while condition; do ... done
until condition; do ... done
case $var in pattern) ... ;; esac
test / [ ... ] (file, string, and integer comparisons)
cd, pwd, exit, true, false, :, read, shift [N], local VAR=value
$(( arithmetic )) -- +, -, *, /, %, and $1..$9 inside
$( command ) and `command` (command substitution, nested)
cmd1 | cmd2 [| cmd3 ...] (pipeline via temporary file)
cmd1 && cmd2, cmd1 || cmd2, cmd1 ; cmd2 (compound commands)
> >> < 2> 2>> 2>&1 1>&2 (I/O redirection)
name() { ... }, function name { ... } (function definitions)
$VAR, ${VAR}, $1..$9, $@, $*, $#, $?, $$, $0
${VAR:-default}, ${VAR:=default}, ${VAR:+alt}
${VAR%pat}, ${VAR%%pat} -- shortest/longest suffix removal
${VAR#pat}, ${VAR##pat} -- shortest/longest prefix removal
${VAR/pat/rep}, ${VAR//pat/rep} -- first/all substitution
${VAR^^}, ${VAR^}, ${VAR,,}, ${VAR,} -- case conversion
${VAR:N:L}, ${VAR:N} -- substring
${#VAR} -- string length
source / . file
REQUIREMENTS
Perl 5.005_03 or later. Core modules only. No external shell required.
BUGS AND LIMITATIONS
The built-in CMD interpreter does not support:
* "FOR /F" with "usebackq" backtick-quoted commands on Windows (the
"cmd /c" subprocess path is untested on Windows)
* "CHOICE", "TIMEOUT", "XCOPY", "ROBOCOPY", "FINDSTR", "SORT", "MORE"
and other external utilities (delegated to the OS)
The built-in SH interpreter does not support:
* Background execution ("&" at end of command)
* Here-documents ("<<")
* Process substitution ("<(cmd)")
Pipeline ("|"), I/O redirection (">" ">>" "<" "2>" "2>>" "2>&1"),
compound commands ("&&" "||" ";"), and function definitions are all
supported.
Section boundary detection is token-based (uppercase vs. lowercase first
token). Mixed-case first tokens are treated as SH.
Please report bugs via the issue tracker:
<https://github.com/ina-cpan/BATsh/issues>
SEE ALSO
BATsh::CMD, BATsh::SH, BATsh::Env
AUTHOR
INABA Hitoshi <ina@cpan.org>
LICENSE
This software is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
( run in 2.157 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )