Add printf, read, break, continue, command, and type builtins#280
Merged
Add printf, read, break, continue, command, and type builtins#280
Conversation
…x path resolution - Replace panic!() in parser (for loop wordlist) and types (arithmetic) with proper error handling/fallback behavior - Replace unreachable!() in parser (and_or lists, boolean operators), execute (assignment operators), and main (script/command dispatch) with descriptive errors - Implement all 14 previously unimplemented file test operators: -b (block special), -c (char special), -g (setgid), -k (sticky bit), -p (named pipe), -s (size > 0), -t (terminal fd), -u (setuid), -G (owned by egid), -N (modified since read), -O (owned by euid), -S (socket), -R (nameref), and None (implicit -n) - Add -e (file exists) and -t (terminal fd) to grammar and parser - Fix file test path resolution to use shell CWD instead of process CWD - Fix critical unwrap() calls in main.rs (current_dir), execute.rs (parse result), uname.rs, touch.rs (DST-ambiguous datetimes), set.rs, and mod.rs (clear command) - Add comprehensive test suite for file test operators (3 new test functions) https://claude.ai/code/session_01GTXgqqxHbE7ACysQDZ9cLU
… type Implement 7 new shell builtins for improved bash compatibility: - break/continue: Loop control flow via sentinel exit codes (-100/-101) that propagate through ExecuteResult::Exit and are caught by while/for loops - : (colon): No-op command that always returns 0 - printf: Format string support with %s, %d, %o, %x, %f, %c, %b specifiers, width/precision/flags, and standard escape sequences - read: Read input with -r (raw) and -p (prompt) flags, field splitting, default REPLY variable - command: Run commands bypassing aliases, -v flag for path lookup - type: Describe how a command name resolves (alias, builtin, or PATH) All builtins include comprehensive tests. https://claude.ai/code/session_01GTXgqqxHbE7ACysQDZ9cLU
Implement 6 more shell builtins for improved bash compatibility: - eval: Parse and execute string arguments as shell commands - source/.: Fix to use context pipes instead of real stdout/stderr, enabling proper pipe capture in tests and subshells. Read file, parse, and execute in current shell context with env change propagation - shift: Shift positional parameters ($1, $2, ...) left by N - local: Declare shell-scoped variables (foundation for future function support) - return: Exit from sourced scripts with specified exit code via ExecuteResult::Exit propagation - trap: Basic signal handling with -l (list signals), -p (print traps), and handler registration acceptance for compatibility All builtins include comprehensive tests. Total: 46 tests passing. https://claude.ai/code/session_01GTXgqqxHbE7ACysQDZ9cLU
…e groups
- Add function_definition parsing (foo() { ... }) with FunctionDefinition AST node
- Store functions in ShellState and execute via execute_shell_function
- Support positional parameters ($1-$N, $#, $@, $*) with save/restore across calls
- Fix grammar: UNQUOTED_ESCAPE_CHAR now excludes SPECIAL_PARAM so $1/$2/etc parse correctly
- Fix RETURN_EXIT_CODE sentinel handling at top level and in function scope
- Sync last_command_exit_code with shell var "?" for proper $? expansion
- Add brace group compound command support
- Add comprehensive tests for functions, positional params, return values, nested calls
https://claude.ai/code/session_01GTXgqqxHbE7ACysQDZ9cLU
- functions.sh: tests for function definitions, positional parameters ($1-$N, $#, $@), nested calls, variable scoping, and function overriding - builtins.sh: tests for eval, shift, local, and brace groups https://claude.ai/code/session_01GTXgqqxHbE7ACysQDZ9cLU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds several important shell builtins and improves file test operator support in the deno_task_shell.
Summary
Implements missing shell builtins (
printf,read,break,continue,command,type) and expands file test operator coverage to support more POSIX-compliant conditional expressions.Key Changes
New Builtins
command -vto locate commands, bypassing aliasesFile Test Operators
Expanded conditional expression support with proper implementations:
-b,-c: Block/character special files (Unix-only)-p: Named pipes (Unix-only)-s: File size greater than zero-u,-g: Setuid/setgid bits-k: Sticky bit-O,-G: File ownership checks (Unix-only)-N: File modified since last read (Unix-only)-t: Terminal file descriptor checksLoop Control Flow
BREAK_EXIT_CODEandCONTINUE_EXIT_CODEsentinel values for signaling loop controlexecute_for_clauseandexecute_while_clauseto handle break/continue properlyOther Improvements
Implementation Details
printfcommand supports both POSIX format specifiers and bash extensions like %breadcommand handles backslash escapes and properly splits input across multiple variableshttps://claude.ai/code/session_01GTXgqqxHbE7ACysQDZ9cLU