arXiv:2606.27733v1 [cs.SE] 26 Jun 2026
BashCoder-R1: Towards Robust and Explainable Bash Code Generation with Robustness-Aware Group Relative Policy Optimization LEI YU∗ , Institute of Software, Chinese Academy of Sciences, China PENG WANG∗ , Institute of Software, Chinese Academy of Sciences, China JIA XU∗ , Institute of Software, Chinese Academy of Sciences, China JINGYUAN ZHANG∗ , Institute of Software, Chinese Academy of Sciences, China XIN WANG∗ , Institute of Software, Chinese Academy of Sciences, China JIAJIA MA, Institute of Software, Chinese Academy of Sciences, China LI YANG† , Institute of Software, Chinese Academy of Sciences, China CHANGZHI DENG, Institute of Software, Chinese Academy of Sciences, China ZENGHUA WANG, Institute of Software, Chinese Academy of Sciences, China FENGJUN ZHANG† , Institute of Software, Chinese Academy of Sciences, China Bash scripts are the cornerstone of system administration, DevOps automation, and Continuous Integration/Continuous Deployment (CI/CD), where their code quality directly impacts system stability and security. In the task of automated Bash script generation using Large Language Models (LLMs), this challenge is amplified by two interconnected failures: first, they operate as unauditable "black boxes" by failing to produce a transparent reasoning process, and second, as a consequence, they generate code riddled with critical robustness vulnerabilities. To address both issues, we propose BashCoder-R1, a novel framework for robust and explainable Bash script generation. It begins with Continual Pre-training (CPT) to specialize the base model on the nuances and programming paradigms of Bash scripting. To construct the data for subsequent stages, we create a dataset of thousands of expert-validated reasoning-and-code samples. Based on this, we then apply Long Chain-of-Thought Supervised Fine-Tuning (L-CoT SFT) to train the model to emulate a human expert’s proactive thinking and risk aversion. Finally, to directly enhance script quality, we employ Robustness-Aware Group Relative Policy Optimization (R-GRPO), a reinforcement learning phase that refines the generation policy by optimizing a weighted reward signal for syntax correctness, code robustness (based ∗ Affiliated with University of Chinese Academy of Sciences, Beijing, China. † Li Yang and Fengjun Zhang are the corresponding authors.
Authors’ Contact Information: Lei Yu, Institute of Software, Chinese Academy of Sciences, Beijing, China, yulei2022@ iscas.ac.cn; Peng Wang, Institute of Software, Chinese Academy of Sciences, Beijing, China, [email protected]. ac.cn; Jia Xu, Institute of Software, Chinese Academy of Sciences, Beijing, China, [email protected]; Jingyuan Zhang, Institute of Software, Chinese Academy of Sciences, Beijing, China, [email protected]; Xin Wang, Institute of Software, Chinese Academy of Sciences, Beijing, China, [email protected]; Jiajia Ma, Institute of Software, Chinese Academy of Sciences, Beijing, China, [email protected]; Li Yang, Institute of Software, Chinese Academy of Sciences, Beijing, China, [email protected]; Changzhi Deng, Institute of Software, Chinese Academy of Sciences, Beijing, China, [email protected]; Zenghua Wang, Institute of Software, Chinese Academy of Sciences, Beijing, China, [email protected]; Fengjun Zhang, Institute of Software, Chinese Academy of Sciences, Beijing, China, [email protected]. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]. Conference acronym ’XX, June 03–05, 2024, Woodstock, NY © 2024 Copyright held by the owner/author(s). Publication rights licensed to ACM. ACM ISBN 978-1-4503-XXXX-X/18/06 https://doi.org/XXXXXXX.XXXXXXX , Vol. 1, No. 1, Article . Publication date: June 2024.
2
Yu et al.
on the static analysis tool shellcheck), and format correctness. On BashBench, a new benchmark of 952 real-world automation tasks (773 single-line commands and 179 multi-line scripts), we evaluate BashCoder-R1 against state-of-the-art baselines. Our results demonstrate exceptional performance across key metrics: SyntaxPass (100.00% / 94.97%), RobustWarnRate (4.01% / 16.47%), RobustPass (95.99% / 79.33%), FuncRate (93.01% / 93.85%), and FullRate (90.04% / 73.18%) for single-line / multi-line tasks, outperforming the strongest baseline DeepSeek-V3.2 (Reasoning) by relative margins of 37.82% and 20.18% in FullRate respectively. Furthermore, human evaluation across three dimensions (Functionality, Robustness, and Clarity) confirms that BashCoder-R1 achieves the highest quality ratings. Additional Key Words and Phrases: Bash Script, Code Generation, Large Language Models, Group Relative Policy Optimization ACM Reference Format: Lei Yu, Peng Wang, Jia Xu, Jingyuan Zhang, Xin Wang, Jiajia Ma, Li Yang, Changzhi Deng, Zenghua Wang, and Fengjun Zhang. 2024. BashCoder-R1: Towards Robust and Explainable Bash Code Generation with Robustness-Aware Group Relative Policy Optimization. In Proceedings of Make sure to enter the correct conference title from your rights confirmation emai (Conference acronym ’XX). ACM, New York, NY, USA, 22 pages. https://doi.org/XXXXXXX.XXXXXXX
1
Introduction
Bash, serving as the domain-specific language (DSL) for Linux systems, is indispensable for critical tasks ranging from system administration and file management to complex CI/CD automation and cloud infrastructure orchestration [31]. Despite its ubiquity, writing correct and efficient Bash scripts remains a formidable challenge compared to General-Purpose Programming Languages (GPPLs) [21]. Unlike the structured and explicit logic of languages like Python or Java, Bash relies heavily on a vast ecosystem of external commands (e.g., awk, sed, grep), each with its own inconsistent argument parsing and steep learning curve. Consequently, developers—even those experienced in GPPLs—often struggle to recall specific command flags or construct complex pipelines, leading to frequent context switching and productivity loss. This difficulty is evidenced by the massive community demand for assistance. Our statistical analysis of Stack Overflow as of March 10, 2025, reveals 93,046 Q&A posts related to the keyword “shell” and 156,721 related to the keyword “bash” [4, 5]. A significant portion of these inquiries seeks solutions for specific automation tasks rather than theoretical explanations, highlighting an urgent need for automated code generation tools that can translate natural language intents into executable Bash scripts. While Large Language Models (LLMs) have achieved remarkable success in code generation and comprehension for mainstream GPPLs [9, 19, 23, 26, 30], their performance in the Bash domain is often hampered by the language’s syntactic density and the requirement for strict functional correctness to avoid dangerous side effects. Despite this, the field of specialized Bash code generation remains relatively underexplored compared to its GPPL counterparts, presenting a critical gap in intelligent software engineering [21, 51, 52]. However, current Code Large Language Models (Code LLMs) lack a deep, contextual understanding of robustness principles when generating Bash scripts, leading to two interconnected failures. First, they fail to produce an explicit reasoning process, operating as "black boxes" that prevent developers from auditing the design logic behind them. Second, this shallow understanding results in code with critical robustness vulnerabilities. For instance, in our motivating example (Figure 1), when a powerful model is tasked to write a script that backs up and cleans old files, it might produce a seemingly correct implementation. However, this implementation could hide several fatal flaws: What if the source directory does not exist? Will the command fail if filenames contain spaces? If the backup command fails due to insufficient disk space, will the command to delete old files still execute, thereby incorrectly deleting data that was not successfully backed up? This error , Vol. 1, No. 1, Article . Publication date: June 2024.
Towards Robust and Explainable Bash Code Generation with Robustness-Aware Group Relative Policy Optimization
3
vividly demonstrates that even top-tier models cannot be trusted for reliable automation script generation without a more structured reasoning capability. Previous research has attempted to mitigate these risks from two main directions. The first is post-hoc analysis, which audits the code after it has been generated. Although using static analysis tools (like shellcheck [14]) is an industry standard, this paradigm has a fundamental weakness. It decouples code generation from quality verification, forcing developers to first receive potentially black-box-generated code and then use a separate tool to find its flaws. This not only disrupts the development workflow but can also lead to complex and inefficient fixes. This approach is inherently reactive, aiming to ’patch fragility’ rather than proactively ’build in robustness’. The second direction focuses on proactive robust code generation [8, 33, 54]. However, these approaches still often lack the explicit, multi-step reasoning required to handle complex logic and fail to produce auditable thought processes. This leaves a critical gap for a model that not only generates robust code but also transparently explains how it achieved that robustness. To bridge these gaps, we propose BashCoder-R1, a framework designed to generate Bash scripts that are not only functional but also inherently explainable, tackling the dual challenges of opaque reasoning and code fragility. Our approach is built on a meticulously designed three-stage training pipeline. First, Continual Pre-training (CPT) is performed on 976,524 Bash and general text instances (809.79M tokens) to build a foundational understanding of Bash syntax. Second, to address the lack of transparency, we employ Long Chain-of-Thought Supervised Fine-Tuning (L-CoT SFT) on 12,334 expert-validated samples (7,005 single-line commands and 5,329 multi-line scripts), which explicitly teaches the model to emulate the thought process of an experienced system administrator, generating a step-by-step reasoning chain (<think>...</think>) before writing the code. Finally, to directly minimize defects, we apply Robustness-Aware Group Relative Policy Optimization (R-GRPO) on 1,824 challenging samples (812 single-line commands and 1,012 multi-line scripts). This reinforcement learning stage directly steers the model’s generation policy towards verifiably correct, robust, and well-structured code by maximizing a programmatic reward function that weights syntax correctness (𝛼 = 0.3), robustness via shellcheck (𝛽 = 0.5), and format compliance (𝛾 = 0.2). We evaluate BashCoder-R1 on BashBench, a new benchmark comprising 952 real-world automation tasks (773 single-line commands and 179 multi-line scripts), each equipped with an automatically generated and manually validated functional test suite. Our experimental results demonstrate that BashCoder-R1 establishes a new state of the art across key metrics: SyntaxPass (100.00% / 94.97%), RobustWarnRate (4.01% / 16.47%), RobustPass (95.99% / 79.33%), FuncRate (93.01% / 93.85%), and FullRate (90.04% / 73.18%) for single-line / multi-line tasks respectively. These results represent a 37.82% relative improvement in FullRate for single-line tasks and 20.18% for multi-line tasks compared to the strongest baseline, DeepSeek-V3.2 (Reasoning). Furthermore, ablation studies confirm that each component (CPT, L-CoT SFT, and R-GRPO) contributes indispensably to the final performance. Human evaluation on 150 randomly sampled test cases reveals that BashCoder-R1’s reasoning chains achieve high-quality ratings (scores 3 to 4 on a 4-point Likert scale) in 82.67% of cases for Functionality, 85.33% for Robustness, and 90.67% for Clarity, significantly outperforming DeepSeek-V3.2 (Reasoning)’s 76.00%, 56.00%, and 85.33% respectively. The main contributions of this paper are as follows: • We propose BashCoder-R1, the first framework to systematically integrate Continual PreTraining (CPT), Long Chain-of-Thought Supervised Fine-Tuning (L-CoT SFT), and RobustnessAware Group Relative Policy Optimization (R-GRPO) for robust and explainable bash code generation. , Vol. 1, No. 1, Article . Publication date: June 2024.
4
Yu et al.
• We construct and release novel, high-quality datasets comprising 12,334 samples for L-CoT SFT (7,005 single-line + 5,329 multi-line) and 1,824 samples for R-GRPO (812 single-line + 1,012 multi-line), along with BashBench, a comprehensive evaluation benchmark of 952 tasks (773 single-line + 179 multi-line) with functional test suites, to foster community research in explainable and robust Bash code generation. • We demonstrate that BashCoder-R1 establishes a new state of the art, achieving a FullRate of 90.04% on single-line tasks and 73.18% on multi-line tasks, outperforming the strongest baseline by relative margins of 37.82% and 20.18% respectively, while human evaluation confirms high-quality ratings across Functionality, Robustness, and Clarity dimensions, proving its superior ability to generate verifiably robust and explainable bash code. 2
Background and Motivation
2.1
Problem Statement
We define the task of Robust Bash Code Generation. Given a natural language prompt 𝑥 that specifies a system administration task, execution constraints, and environmental details, the goal is to generate executable Bash code 𝑦 (ranging from single-line commands to complex scripts). Unlike traditional code generation, which directly maps the input to code via 𝑃 (𝑦|𝑥), we formulate the problem as a two-stage generation process incorporating an explicit reasoning chain 𝑟 . The model must first generate a structured reasoning plan 𝑟 that explicitly analyzes robustness requirements (e.g., error handling mechanisms, permission checks, and environment isolation) and subsequently generate the code 𝑦 conditioned on both the prompt and the reasoning plan. Formally, the objective is to model the joint probability: 𝑃 (𝑦, 𝑟 |𝑥) = 𝑃 (𝑟 |𝑥) · 𝑃 (𝑦|𝑥, 𝑟 )
(1)
where 𝑟 represents the intermediate "thought process" ensuring that the resulting code 𝑦 is not only functionally correct but also robust against runtime anomalies in production environments. 2.2
Motivations
Bash script development demands rigorous robustness due to its nature of directly manipulating production environments. However, existing Code LLMs often fail to address this, treating script generation as a standard coding task without the necessary structured reasoning. This oversight leads to two critical limitations that motivate our work: (1) the absence of explicit, auditable robustness reasoning, leaving developers with unverifiable "black box" code, and (2) the resulting generation of code with critical robustness issues, stemming from a shallow understanding of shell environment complexities like variable expansion and error handling. To illustrate these limitations, consider the following detailed user prompt given to both a standard Code LLM and our reasoning-enhanced model: User Prompt: Write a complete Bash script with proper structure, error handling, comments, and best practices to solve the given problem. Create a script to automatically check for and apply updates to the PlexConnect application from its Git repository. The script should first check for available updates by fetching the latest changes and comparing them to the current local version. If updates are found, it must stop the PlexConnect service via launchctl, pull the updates, and then restart the service. After restarting, the script should display the contents of the PlexConnect.log file to confirm the service status. If no updates are available, it should simply output that no updates were found.
, Vol. 1, No. 1, Article . Publication date: June 2024.
Towards Robust and Explainable Bash Code Generation with Robustness-Aware Group Relative Policy Optimization
5
The script must ensure the system PATH is correctly configured to include necessary Git and system binaries before performing any operations. All actions must be performed within the correct PlexConnect server directory, using appropriate delays to allow processes to complete.
Write a complete Bash script with proper structure, error handling, comments, and best practices to solve the given problem. Create a script to automatically check for and apply updates to the PlexConnect application from its Git repository. The script should first check for available updates by fetching the latest changes and comparing them to the current local version. If updates are found, it must stop the PlexConnect service via launchctl, pull the updates, and then restart the service. After restarting, the script should display the contents of the PlexConnect.log file to confirm the service status. If no updates are available, it should simply output that no updates were found. The script must ensure the system PATH is correctly configured to include necessary Git and system binaries before performing any operations. All actions must be performed within the correct PlexConnect server directory, using appropriate delays to allow processes to complete.
Qwen2.5-Coder-7B-Instruct
BashCoder-R1
Here's an example of how the script might look:
<think> Let me create a Bash script to meet this requirement step by step.
#!/bin/bash # Define variables PLEXCONNECT_DIR="/path/to/plexconnect" ❌ Incomplete Path LOG_FILE="$PLEXCONNECT_DIR/PlexConnect.log" ❌ Hardcoded Paths # Check if required commands are installed ⚠ Partial Edge Cases if ! command -v git &> /dev/null; then echo "Git could not be found, please install it." exit 1 fi # Change to PlexConnect directory cd "$PLEXCONNECT_DIR" || { echo "Failed to change directory to $PLEXCONNECT_DIR"; exit 1; } # Fetch latest changes from Git repository git fetch origin master # Compare current branch to remote branch if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/master)" ]; then # Stop PlexConnect service sudo launchctl unload ❌ Wrong Method /Library/LaunchDaemons/com.plexapp.plugins.plexconnect.plist # Pull updates git pull origin master
❌ No Fallback
# Restart PlexConnect service sudo launchctl load /Library/LaunchDaemons/com.plexapp.plugins.plexconnect.plist # Display log file contents cat "$LOG_FILE" else echo "No updates found." fi
❌ Requires Modifications
This script provides a basic framework for checking for and applying updates to PlexConnect. However, you may need to modify it to fit your specific requirements or environment.
Think First
Step 1: First, I need to understand the core requirements. The script must check for Git updates to PlexConnect, stop the service, apply updates, restart the service, and display logs. I'll start by setting up proper error handling with set -euo pipefail to make the script robust. Then I need to configure the system PATH to include necessary binaries like Git and launchctl. Step 2: Next, I'll implement the directory change and validation. The script must run within the PlexConnect server directory, so I'll use cd with error checking. I need to verify that the directory exists and that we have the necessary permissions. Step 3: Now I'll implement the update checking logic. I need to fetch the latest changes from Git and compare them to the current local version. I'll use git fetch and git log to compare commit hashes. Step 4: For the service management, I need to handle both stopping and starting the PlexConnect service via launchctl. I'll add proper error checking for each operation. After starting the service, I need to include a delay to allow the service to initialize properly before checking the logs. Finally, I'll display the contents of PlexConnect.log to confirm the service status. Step 5: I'll review the complete script to ensure it follows best practices. I'll add clear echo statements for user feedback, proper error messages redirected to stderr, and appropriate exit codes. I'll also verify that all Git and launchctl commands are properly quoted and that the script handles edge cases like missing directories or failed service operations gracefully. Step 6: Finally, I'll validate that the script structure makes logical sense. The flow should be: check prerequisites → change directory → validate → check for updates → perform updates if needed → display status. </think>
Then Output
<answer> #!/bin/bash # Script to automatically check for and apply updates to PlexConnect from Git set -euo pipefail
# Ensure required binaries are available export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" ✅ Complete PATH ✅ Configurable Directory # Enter PlexConnect server directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR/PlexConnectServer" || { echo "Directory error"; exit 1; } echo "Checking for updates..." git fetch # Compare remote and local commits LATEST_COMMIT=$(git rev-parse origin/master) CURRENT_COMMIT=$(git rev-parse HEAD) if [[ "$LATEST_COMMIT" != "$CURRENT_COMMIT" ]]; then echo "Updates found. Applying..." # Stop service before updating ✅ Correct Command launchctl stop com.plex.plexconnect || true ✅ Error Recovery sleep 2 # Pull updates git pull # Restart service after update launchctl start com.plex.plexconnect sleep 5 # Show log after restart if [[ -f PlexConnect.log ]]; then ✅ Comprehensive Edge Cases cat PlexConnect.log else echo "PlexConnect.log not found" fi else echo "No updates available." ✅ Ready to Deploy fi </answer>
Fig. 1. A motivating example to illustrate the limitations of non-reasoning Code LLMs in bash script generation, demonstrating the advantages of reasoning-enhanced Code LLMs.
Motivation 1: Lack of Explicit Robustness Reasoning. Most existing Code LLMs lack reasoning steps and simply treat Bash script generation as a traditional code generation task. This "black box" approach is perilous. When a model does not articulate its reasoning, developers cannot verify the assumptions behind the code. As shown in the motivating example (Figure 1), when presented with the detailed prompt above, a standard LLM like Qwen2.5-Coder-7B-Instruct directly outputs a code implementation. This leaves developers unable to understand its design principles and potential risks. For instance, why were hardcoded paths chosen instead of a configurable variable? Why was there no error handling for the service stop command, despite the prompt explicitly requesting it? In contrast, BashCoder-R1 demonstrates its robustness considerations to developers through an explicit reasoning process (<think>...</think>). It articulates its plan step-by-step: "I’ll start by setting up proper error handling with set -euo pipefail... Then I need to configure the system PATH...", "For the service management, I need to handle both stopping and starting the PlexConnect service via launchctl. I’ll add proper error checking for each operation...". This transparent reasoning process enables programmers to understand, verify, and audit the reliability of the generated code rather than blindly trusting model outputs. , Vol. 1, No. 1, Article . Publication date: June 2024.
6
Yu et al.
Motivation 2: Generation of Code with Critical Robustness Issues. This lack of explicit reasoning directly leads to the second critical limitation: the generation of code that is not merely suboptimal, but functionally flawed and fragile. The "black box" approach, devoid of a deep understanding of shell environment complexities, results in scripts that are unsafe for production. As illustrated in Figure 1, the script produced by the standard Code LLM is riddled with severe robustness issues that make it undeployable, failing to meet multiple requirements from the prompt: (1) It uses a hard-coded and non-standard path (/tmp/PlexConnect), which undermines portability and may cause conflicts. (2) It employs a dangerous and improper service management command (killall Python), which can unintentionally terminate other critical processes and bypasses the requested launchctl graceful shutdown, risking data corruption. (3) It performs a blind git pull operation without first verifying the directory’s state, which will fail if the local repository has uncommitted changes. (4) It lacks any error handling or status checks for critical commands like cd, killall, and git pull, directly violating the prompt’s requirement for "proper structure, error handling... and best practices." This allows the script to fail silently or proceed in an inconsistent state. (5) It makes unsafe assumptions about the environment, such as the existence of the git command or the initial running state of the service, and fails to configure the PATH as requested. In stark contrast, BashCoder-R1, guided by its explicit robustness reasoning, systematically identifies and addresses these issues to produce a production-ready solution that fully adheres to the prompt. There is a clear correspondence between its reasoning and the final, robust code: • To address hard-coded paths: Its reasoning leads it to use a configurable variable for the application path, promoting reusability and adhering to best practices. • To address improper service management: It correctly identifies and uses launchctl as requested for proper macOS service management, implementing graceful stop/start operations. • To address blind operations: Its reasoning plan includes checking the git repository’s status to ensure it is clean before attempting a git pull, thus preventing predictable failures. • To address the lack of error handling: It begins by setting set -euo pipefail for global safety and adds explicit status checks after each critical operation, ensuring the script fails immediately and informatively, fulfilling a core part of the user’s request. • To address unsafe environmental assumptions: The reasoning explicitly mentions configuring the PATH, as requested, and checking command success, showing a deep awareness of the execution environment. By systematically resolving each potential failure point identified during its reasoning phase, the generated script is inherently robust and deployable, eliminating the need for extensive manual hardening and fully satisfying the user’s detailed requirements. 3
Approach
This section details our end-to-end approach for Dataset Construction, CPT, L-CoT SFT, and Reinforcement Learning with R-GRPO. The Qwen2.5-Coder-7B serves as our base model, selected for its superior coding capabilities [16] and the Qwen family’s superior adaptability to reinforcement learning (RL) compared to counterparts like Llama [44]. As shown in the figure, we begin by building a high-quality dataset with explicit robustness considerations and multi-step reasoning traces, followed by continual pre-training on normalized Bash code to instill syntactic and structural knowledge. Next, we employ Long Chain-of-Thought Supervised Fine-Tuning to , Vol. 1, No. 1, Article . Publication date: June 2024.
Towards Robust and Explainable Bash Code Generation with Robustness-Aware Group Relative Policy Optimization
7
teach the model explicit reasoning about robustness requirements. Finally, we apply R-GRPO reinforcement learning to further align the model with rigorous robustness, compliance, and functionality standards, leveraging automated reward signals and KL-regularized policy updates.
SFT & R-GRPO Data Construct
Continual Pre-Training
Prompt
Pre-trained LLM
Analyze the user request and original command to generate a robust, production-ready Bash solution. Explain the reasoning and provide the code in a structured format. User Request: {user_instruction} Original Command: {original_code}
DeepSeek-V3
Code LLM: Qwen2.5-Coder-7B
Maximum 3 times
Bash Syntax Check: Run bash -n [script] to find syntax errors.
Continual Pre-Training Continual Pre-Training Data
Shellcheck Analysis: Run shellcheck [script] for best practices, bugs, and style issues.
Domain
Automated Quality & Syntax Check
General
{ "instruction": "Develop a productionready Bash solution that...", "input": "User request text...", "output":"<think>...</think>\n<answer>... </answer>", "complexity": "complex", "original_code": "cat file.txt" }
Long Chain-of-Thought Supervised Fine-Tuning
Bash Task Instruction (Query)
Prompt
Generate a reliable Bash solution with proper syntax and best practices for the given task. Ensure the implementation follows best practices for error handling and security. {bash task}
Response
<think> Let me analyze the requirements one by one. To design a reliable script, I should first handle arguments, then validate the source directory exists, then create a timestamped archive... </think> <answer> #!/bin/bash # Script to archive old log files... ... </answer>
CPT Model
Robustness-Aware Group Relative Policy Optimization
SFT Model
Policy Model�
O1 O2 O3 O4 ... OG Syntax Check
Robustness Check
[Reward Aggregation] α₁,α₂,α₃
R1 R2 ... RG
Normalization
GRPO Loss
Reference ❄ Model️
(Clip+KL)
[Policy Update]
SFT & R-GRPO Training Data
CPT Model
Format Check
Final Model
Fig. 2. Overview of our BashCoder-R1 pipeline.
3.1
Dataset Construction
3.1.1 CPT Dataset Generation Process. For our Continual Pre-training dataset, we followed the approach in [6] and integrated Bash-related data from multiple sources: (1) The complete collection of Linux manual pages (Man Pages), containing detailed command descriptions and usage examples; (2) Stack Overflow question-answer pairs tagged with "bash", "shell", and "linux"; (3) Highly-starred Bash project source code from GitHub; (4) Curated shell script discussions from Unix & Linux Stack Exchange. We extracted a total of 1,013,135 Bash commands and scripts from these sources. To ensure uniqueness, scripts were filtered using a Jaccard Index [1] similarity threshold of 0.9, eliminating those with over 90% token similarity. After deduplication, 676,524 unique Bash scripts remained. The threshold of 0.9 was adopted following prior work [39, 51], which used this value to identify and remove near-duplicate code snippets. 3.1.2 SFT Dataset Generation Process. Our Supervised Fine-Tuning (SFT) dataset is constructed through a rigorous, multi-stage process designed to produce high-quality triplets of (bash task instruction, thinking chain, bash code). The generation pipeline is tailored differently for single-line commands and multi-line scripts to maximize data quality and relevance. • For single-line Bash commands, we start with a pre-existing dataset of instructioncommand pairs. The existing Bash command is first validated for correctness and robustness using bash -n for syntax and shellcheck for static analysis. If a command fails, we leverage the LLM to attempt a correction up to three times, and commands that cannot be successfully validated are discarded. For each validated instruction-command pair, we then prompt the LLM to generate an explanatory reasoning chain (<think>...</think>). This step effectively reverse-engineers the expert thought process behind the command, articulating key , Vol. 1, No. 1, Article . Publication date: June 2024.
8
Yu et al.
considerations about its syntax, options, and potential edge cases, resulting in a complete (original instruction, generated <think>, validated command) triplet. • For multi-line Bash scripts, our process begins with a corpus of code-only script samples. Each script first undergoes a comprehensive validation pipeline combining static analysis (bash -n and shellcheck) with dynamic functional validation. For the dynamic part, we guide the LLM to generate a self-contained, executable test case, which is then run in a sandboxed environment. Scripts that fail any validation stage go through a correction loop of up to three attempts; if still unsuccessful, they are discarded. Once a script is fully validated, we task the LLM with sequentially generating a concise, natural-language instruction describing its functionality, followed by a detailed reasoning chain (<think>...</think>). This reasoning articulates the script’s logic, structure, and robustness measures. The procedure culminates in a complete (generated instruction, generated <think>, validated script) triplet. In parallel with code validation, our team of experts conducts a meticulous manual review and modification of the <think>...</think> reasoning chain generated by DeepSeek-V3.2, ensuring its logic is clear, its steps are reasonable, and it is highly consistent with the final validated code implementation. The review and modification were conducted by six senior experts with extensive experience in Bash scripting and Linux system administration. All experts have over 5 years of professional experience in shell script development, regularly write production-level Bash scripts in their daily work, and are proficient in identifying common robustness issues and best practices. The experts were organized into three independent two-person teams to ensure consistent and unbiased evaluation. Through this dual validation mechanism for both code and reasoning, we ensure the overall high quality of every sample in the SFT dataset. 3.1.3 R-GRPO Dataset Generation Process. The Reward-Grouped Preference Optimization (RGRPO) dataset is a subset selected from the constructed SFT dataset, specifically intended for preference learning focused on the model’s reasoning abilities. The selection process relies on a quantitative complexity scoring model designed to automatically identify and extract the most challenging "hard samples." This scoring model applies different evaluation criteria depending on whether a sample is a single-line command or a multi-line script. For single-line commands, the score is primarily based on the length of the command itself, the length of the reasoning process, and the number of advanced syntax elements it contains, such as pipes, logical operators, and command substitutions. For multi-line scripts, however, the score places greater emphasis on the overall scale and structure of the code; in addition to considering the total number of lines and reasoning length, it deeply analyzes structural complexity, such as the total count of functions, loops, and conditional statements, as well as their nesting depth. In both evaluation methods, the length of the code and the reasoning are consistently treated as crucial factors. After a composite complexity score is calculated for each SFT sample using this system, the samples with the highest scores are selected to form the R-GRPO dataset. To ensure dataset quality, we employed a stratified validation strategy across the entire SFT corpus. All 1,824 samples designated for R-GRPO underwent complete manual review by the expert team due to their high complexity, while an additional 1,500 samples were randomly selected from the SFT dataset for quality inspection. Each reviewed sample was independently evaluated by two experts to verify reasoning coherence, functional correctness, and reasoning-code consistency. Samples that did not meet quality standards were refined and corrected by the experts to ensure the final dataset met our rigorous quality requirements. , Vol. 1, No. 1, Article . Publication date: June 2024.
Towards Robust and Explainable Bash Code Generation with Robustness-Aware Group Relative Policy Optimization
3.2
9
Continual Pre-training (CPT)
During continual pre-training, we use only pure Bash code, excluding comments and documentation, to prevent the model from memorizing non-functional text and to focus the learning on syntactic and structural patterns. Each script is decomposed into overlapping code windows of up to 2048 tokens. Each window is used as a training instance for next-token prediction. The training objective is the standard left-to-right language modeling loss: 𝑇
𝑁
LCPT = −
𝑖 1 ∑︁ ∑︁ log 𝑃 (𝑥𝑖,𝑗 | 𝑥𝑖,< 𝑗 ) 𝑁 𝑖=1 𝑗=1
(2)
where 𝑁 is the total number of code windows in the pre-training corpus, 𝑇𝑖 is the length of the 𝑖-th window, and 𝑥𝑖,𝑗 is the 𝑗-th token in window 𝑖. We train the model for two epochs using the AdamW optimizer with a learning rate of 1 × 10−5 , batch size of 64, and a sequence length cutoff of 2048 tokens. During this phase, the model is exposed to a vast corpus of Bash scripts, allowing it to internalize fundamental syntactic structures, common command idioms (e.g., grep, awk, sed), control flow statements (if, for, while), and shell-specific patterns like pipelines and I/O redirection. No reasoning or natural language instruction is present in this phase. 3.3
Long Chain-of-Thought Supervised Fine-Tuning (L-CoT SFT)
The purpose of the Long Chain-of-Thought (L-CoT) Supervised Fine-Tuning stage is to explicitly endow the model with the capacity to perform the multi-step reasoning required for robust Bash script generation. Each training sample consists of a natural language instruction, a detailed stepwise reasoning chain enclosed in <think>...</think>, and a standalone Bash implementation enclosed in <answer>...</answer>. The output sequence is strictly required to begin with a multi-sentence, logically ordered reasoning trace, followed by a complete script implementation. The supervised fine-tuning loss is: 𝑀
LSFT = −
𝐿
𝑘 1 ∑︁ ∑︁ log 𝑃 (𝑦𝑘,𝑙 | 𝐼𝑘 , 𝑦𝑘,<𝑙 ) 𝑀
(3)
𝑘=1 𝑙=1
where 𝑀 is the number of samples in the fine-tuning dataset, 𝐼𝑘 is the input instruction for the 𝑘-th sample, and 𝑦𝑘,𝑙 is the 𝑙-th token of the corresponding ground-truth output (containing both reasoning and code). The model is trained for three epochs with a learning rate of 1 × 10−5 , a batch size of 8, and a maximum sequence length of 8192 to accommodate long reasoning chains. All ground-truth samples in the SFT dataset are guaranteed to be syntactically correct (bash -n) and free of robustness warnings from shellcheck. This stage imparts the model with the initial ability to decompose high-level requirements into explicit robustness logic steps and to realize these as functional, robust, and syntactically correct code. After SFT, the model can generate code that is not only correct but also accompanied by an auditable reasoning trace, providing the foundation for downstream RL alignment. 3.4
Robustness-Aware Group Relative Policy Optimization (R-GRPO)
The R-GRPO stage acts as a targeted refinement process, aligning the model with the complex, multifaceted objectives of real-world script development that are difficult to capture with supervised learning alone. For each input instruction, the model’s task is to generate a response that contains both: (1) a Long Chain-of-Thought (<think>) reasoning process that explicitly outlines the robustness considerations and implementation plan, and (2) the final, executable Bash script (<answer>). , Vol. 1, No. 1, Article . Publication date: June 2024.
10
Yu et al.
During training, we sample a group of 𝐺 candidate outputs from the current policy network 𝜋𝜃 for each prompt. Each candidate is then subjected to a rigorous, automated evaluation to calculate its reward: • Syntax Check (𝑅syntax ): This is the most foundational prerequisite for any script. The generated code is checked using bash -n. A successful check (𝑅syntax = 1) signifies that the code is syntactically valid. A failure (𝑅syntax = 0) indicates a fundamental flaw, rendering the output useless. • Robustness Rule Check (𝑅robustness ): This is the most critical component, directly targeting the core challenge of robust script generation. We use the static analysis tool shellcheck to scan the code for known bad smells and vulnerability patterns. These checks are intentionally designed to be conservative, prioritizing flagging any potentially unsafe patterns. For example, this check verifies if the model correctly uses double quotes for all variable expansions (e.g., "$var" instead of $var to prevent word splitting and globbing), avoids unsafe command substitutions, checks the exit codes of critical commands (e.g., using if ! command; then ...), and uses mktemp for secure temporary file creation. A script that passes shellcheck with no errors or warnings receives 𝑅robustness = 1; otherwise, it receives 𝑅robustness = 0. • Format Compliance (𝑅format ): This reward ensures the model maintains its explainability. The output must contain a well-structured <think> block with substantive reasoning (at least three distinct logical steps) followed by a distinct <answer> block. This structure provides a crucial cognitive scaffold for developers, allowing them to audit the model’s robustness logic before trusting its code. A compliant format yields 𝑅format = 1. The total reward 𝑅 for each candidate is a weighted sum of these three binary scores, reflecting their relative importance: 𝑅 = 𝛼 · 𝑅syntax + 𝛽 · 𝑅robustness + 𝛾 · 𝑅format
(4)
We set the weights to (𝛼, 𝛽, 𝛾) = (0.3, 0.5, 0.2), prioritizing robustness (𝑅robustness ) above all else, as a single defect can compromise an entire system’s stability. The policy is updated using the R-GRPO objective, which combines the clipped policy ratio surrogate loss with a KL penalty to prevent large deviations from a reference policy (typically the SFT model). The overall R-GRPO loss is: # " 𝐺 |𝑜 | 𝑖 1 ∑︁ ∑︁ min 𝑟𝑡 (𝜃 )𝐴ˆ𝑖,𝑡 , clip(𝑟𝑡 (𝜃 ), 1 − 𝜖, 1 + 𝜖)𝐴ˆ𝑖,𝑡 𝐽R-GRPO (𝜃 ) = −E𝑞,{𝑜𝑖 }𝐺 ∼𝜋𝜃 𝑖=1 old 𝐺 𝑖=1 𝑡 =1 +𝜆𝐷 KL (𝜋𝜃 ∥𝜋 ref )
(5)
𝜋 (𝑜 |𝑞,𝑜 ) where 𝑟𝑡 (𝜃 ) = 𝜋𝜃 𝜃 (𝑜𝑖,𝑡𝑖,𝑡 |𝑞,𝑜𝑖,<𝑡 is the probability ratio, 𝐴ˆ𝑖,𝑡 is the normalized advantage estimated 𝑖,<𝑡 ) old from the group rewards, 𝜖 is the clipping hyperparameter, and 𝜆 is the KL penalty coefficient. In essence, the R-GRPO method constructs an efficient, automated "trial-and-error" learning environment. When tasked with a prompt, the model generates a diverse group of potential solutions. The system then acts as an automated "code reviewer," rigorously evaluating each attempt: solutions that are syntactically correct, use robust patterns like set -euo pipefail, quote all variables, and wrap critical operations in conditional blocks are given a high reward. Conversely, those with syntax errors or robustness flaws receive a low reward. This reward signal directly guides the model’s parameter updates, reinforcing behaviors that lead to high-quality outputs while discouraging those that result in problems. Through this continuous, automated iteration loop, R-GRPO compels the model to not only learn "how to write code," but more importantly, to internalize the core development principle of "why it must be written this way to be robust."
, Vol. 1, No. 1, Article . Publication date: June 2024.
Towards Robust and Explainable Bash Code Generation with Robustness-Aware Group Relative Policy Optimization 11
3.5
Inference
During the inference phase, to ensure the determinism and reproducibility of the generated Bash scripts, we employ a greedy decoding strategy. Specifically, at each generation step, we select the token with the highest probability from the model’s output distribution (equivalent to setting the temperature parameter 𝑇 = 0). While stochastic sampling methods (e.g., Top-𝑘 or Top-𝑝 sampling) can enhance diversity, precision and logical rigor are paramount in Bash scripting tasks. Greedy decoding maximizes the utilization of the policy optimized via R-GRPO, outputting the code sequences with the highest confidence. This approach minimizes the risk of syntax errors or hallucinated commands. Furthermore, this deterministic inference strategy ensures that our evaluation results on the benchmark are stable and fair. 4 4.1
Experiments Research Questions
To evaluate our BashCoder-R1, we conduct experiments to answer the research questions: • RQ1: Overall Performance. How does BashCoder-R1 perform in generating functionally correct and robust Bash scripts compared to state-of-the-art code generation models? • RQ2: Ablation Study. What are the respective contributions of the three core components to the model’s final performance: Continual Pre-training (CPT), Long Chain-of-Thought Supervised Fine-Tuning (L-CoT SFT), and Robustness-Aware Group Relative Policy Optimization (R-GRPO)? • RQ3: Human Evaluation of Reasoning Chains. How is the quality of the reasoning chains generated by BashCoder-R1 in terms of their functionality, robustness considerations, and clarity? • RQ4: Case Study. Through a concrete case study, what are the fundamental differences between the reasoning and code generation processes of BashCoder-R1 and baseline models when addressing robustness issues? 4.2
Datasets
Continual Pre-training (CPT): We employ a dataset derived from Dong et al. [6], which includes 676,524 unique Bash scripts from GitHub and Linux documentation (554.40M tokens). To enhance domain diversity, we further add 300,000 instances from general code, mathematics, and both English and Chinese text (255.39M tokens), resulting in a total of 976,524 instances (809.79M tokens). Long Chain-of-Thought SFT (L-COT SFT): We constructed a large-scale dataset of 12,334 high-quality samples for the Long Chain-of-Thought Supervised Fine-Tuning stage. This dataset comprises 7,005 single-line Bash commands and 5,329 multi-line Bash scripts. Each sample contains an (instruction, <think>, <answer>) tuple. These samples were initially generated by DeepSeek-V3.2 and then rigorously reviewed and revised by three senior system administrators to ensure they are functionally correct, pass shellcheck (with no errors or warnings), and feature clear, sound reasoning. Robustness-Aware Group Relative Policy Optimization (R-GRPO): For the RobustnessAware Group Relative Policy Optimization stage, we utilized a curated subset of 1,824 challenging samples, consisting of 812 single-line commands and 1,012 multi-line scripts. These samples were specifically selected to optimize the model’s ability to handle complex logic and robustness requirements. Evaluation: We built a novel evaluation benchmark, BashBench, comprising 952 tasks that are completely isolated from all training data. These tasks are divided into 773 single-line bash , Vol. 1, No. 1, Article . Publication date: June 2024.
12
Yu et al.
commands and 179 multi-line bash scripts, covering a wide range of real-world scenarios, from simple file operations to complex CI/CD automation and cloud service interactions. To enable automated verification of functional correctness, we developed a sophisticated, LLM-driven framework to generate a unique execution-based test suite for each task. This automated construction process is applied uniformly to both single-line commands and multi-line scripts. For each task, we prompt a powerful LLM (DeepSeek-V3.2) to create a self-contained, executable test script. To ensure safety and prevent side effects, each test is executed within a temporary, isolated directory created via mktemp -d, with an automated cleanup mechanism using trap. For tasks involving interactions with the file system or external programs, the framework employs “creative mocking,” instructing the LLM to generate necessary mock files, directory structures, or simple executable stubs. This is crucial for functionally testing both simple commands and complex scripts with external dependencies. Furthermore, the framework incorporates a robust automated repair loop: if a generated test fails, its output, errors, and exit code are fed back to the LLM, which then attempts to correct the test script in an iterative process. To ensure the utmost quality and correctness of our benchmark, every single one of the 952 generated test suites underwent a meticulous manual review. This comprehensive audit verified that each test accurately reflected the task’s original intent, possessed robust evaluation logic, and employed correct assertions. 4.3
Baselines
We compare BashCoder-R1 against a wide range of baselines which can be categorized as follows: • General-purpose LLMs: Models from the LLaMA series [10] (Llama-3.1-8B-Instruct, Llama3.2-1B/3B-Instruct) and the Qwen series [49] (Qwen2.5-3B/7B/14B/32B-Instruct, Qwen3-32B), as well as Claude-Sonnet-4.5 [2]. • Code LLMs: Models from the DeepSeek-Coder series [13] (DeepSeek-Coder-6.7B-Instruct), the Qwen2.5-Coder series [16] (Qwen2.5-Coder-3B/7B/14B/32B-Instruct, Qwen3-Coder-30BA3B), and the CodeLLaMA series [36] (CodeLlama-7B/13B/34B-Instruct). • Reasoning LLMs: Models from the QwQ series [41] (QwQ-32B) and DeepSeek series [22] (DeepSeek-V3.2 (Reasoning)), to evaluate reasoning and code generation capabilities without domain-specific fine-tuning. 4.4
Metrics
We employ the following five core metrics to comprehensively evaluate model performance: • SyntaxPass (%) ↑: Percentage of scripts passing bash -n syntax check, measuring the ability to generate syntactically correct Bash code. • RobustWarnRate (%) ↓: Percentage of syntactically correct scripts triggering shellcheck issues (errors, warnings, or info). Lower is better, reflecting code robustness and best practice adherence. • RobustPass (%) ↑: Percentage of scripts passing both syntax check and shellcheck with no issues, indicating compliance with shell scripting best practices and security standards. • FuncRate (%) ↑: Percentage of scripts passing functional test suites in BashBench, validating whether generated code truly implements required functionality. • FullRate (%) ↑: Percentage of scripts satisfying all three conditions: syntactic correctness, robustness, and functional correctness. This is the most stringent metric reflecting productionlevel deployability. For RQ3, we conduct human evaluation where domain experts rate the reasoning chain quality across Functionality, Robustness, and Clarity using a 4-point Likert scale (1=Poor, 2=Fair, 3=Good, 4=Excellent). , Vol. 1, No. 1, Article . Publication date: June 2024.
Towards Robust and Explainable Bash Code Generation with Robustness-Aware Group Relative Policy Optimization 13
4.5
Implementation Details
We employ Qwen2.5-Coder-7B-Instruct as our backbone model. All training experiments are conducted on a computational node equipped with 8 NVIDIA H800 GPUs (80GB memory each). For the CPT and L-CoT SFT stages, we utilize the LlamaFactory framework [56] integrated with DeepSpeed ZeRO-3 [35] to facilitate full-parameter fine-tuning. We optimize parameters using AdamW [25] (𝛽 1 = 0.9, 𝛽 2 = 0.99, 𝜖 = 1e−8) with a cosine learning rate schedule. Specifically, for CPT, we set the learning rate to 1e−5, batch size to 64, gradient accumulation steps to 16, and train for 2 epochs with a cutoff length of 2,048. For L-CoT SFT, we maintain the learning rate at 1e−5 but adjust the batch size to 8, gradient accumulation steps to 8, and extend the cutoff length to 8,192 to accommodate longer reasoning chains over 3 epochs. For the R-GRPO stage, we implement our training pipeline based on the Logic-RL framework [48] and VeRL [38]. Initialized from the L-CoT SFT checkpoint, the model is trained for 5 epochs with a learning rate of 3 × 10−7 . We set the number of parallel rollouts to 8 and enforce a KL divergence constraint with a coefficient of 0.001 to stabilize training. To maximize GPU throughput, we enable gradient checkpointing and full offloading for parameters, gradients, and optimizer states. The maximum prompt and response lengths are set to 24,576 and 2,048, respectively. During inference, we employ a greedy decoding strategy (do_sample=false) across all benchmarks to eliminate randomness and ensure the reproducibility of our results. 4.6
Overall Performance (RQ1)
To answer RQ1, we evaluated BashCoder-R1 and all baseline models on BashBench. The results are presented in Table 1. BashCoder-R1 outperforms all baselines on both task types. For single-line commands, it achieves 95.99% RobustPass, representing a 72.88% relative improvement over the strongest baseline DeepSeek-V3.2 (67.92%). Most critically, BashCoder-R1 attains a 90.04% FullRate, meaning 9 out of 10 solutions are immediately deployable, outperforming DeepSeek-V3.2 by 37.82%. The reasoning model QwQ-32B achieves only 23.67% FullRate, demonstrating that generic reasoning without domain-specific robustness training is insufficient. For multi-line scripts, BashCoder-R1 maintains dominance with 79.33% RobustPass (25.69% relative improvement over DeepSeek-V3.2’s 63.13%) and 73.18% FullRate (20.18% relative improvement over DeepSeek-V3.2’s 60.89%). The superiority demonstrates the effectiveness of our approach: CPT establishes the foundational Bash syntax knowledge, L-CoT SFT enables the model to explicitly reason about robustness pitfalls during generation, and R-GRPO directly optimizes scripts against shellcheck validation with 𝛽 = 0.5 for robustness rewards, eliminating errors that reasoning alone cannot address. Baseline models consistently fail on robustness despite reasonable functionality, with even the strongest baseline DeepSeek-V3.2 showing 32.08% and 36.87% robustness failure rates for single-line and multi-line scripts respectively, confirming that robustness cannot emerge without explicit optimization. Answer to RQ1: BashCoder-R1 outperforms all baselines, achieving 90.04% and 73.18% FullRate on single-line and multi-line tasks (37.82% and 20.18% improvements over DeepSeek-V3.2), validating the effectiveness of our post-training pipeline.
4.7
Ablation Study (RQ2)
To investigate the contribution of each component, we conducted an ablation study. We evaluated several variants of BashCoder-R1: 1) using only L-CoT SFT (w/o CPT & R-GRPO); 2) performing , Vol. 1, No. 1, Article . Publication date: June 2024.
14
Yu et al.
Table 1. Performance comparison on BashBench for single-line command tasks. ↑ indicates higher is better, and ↓ indicates lower is better. * indicates reasoning mode.
Model
SyntaxPass ↑ RWarnRate ↓ RobustPass ↑ FuncRate ↑ FullRate ↑ General LLMs
Llama-3.2-1B-Instruct Llama-3.2-3B-Instruct Llama-3.1-8B-Instruct Qwen2.5-14B-Instruct Qwen2.5-32B-Instruct
84.22 92.37 95.86 99.22 97.57
73.89 64.29 46.96 59.58 53.51
21.99 32.99 50.84 40.10 45.41
89.91 93.01 92.88 93.01 93.01
20.31 30.66 48.77 38.42 43.73
45.67 20.83 52.13 48.25 45.67 45.92 51.75 55.50
29.88 67.27 91.85 92.37 92.88 93.01 93.01 45.41
25.10 20.31 50.06 45.80 42.95 43.86 49.42 26.00
25.49 67.92 95.99
58.34 93.01 93.01
23.67 65.33 90.04
Code LLMs CodeLlama-13B-Instruct CodeLlama-34B-Instruct DeepSeek-Coder-6.7B-Inst Qwen2.5-Coder-3B-Inst Qwen2.5-Coder-7B-Inst Qwen2.5-Coder-14B-Inst Qwen2.5-Coder-32B-Inst Qwen3-Coder-30B-A3B
60.28 65.20 98.45 97.28 94.57 99.35 97.54 82.66
15.02 68.06 47.04 50.40 51.71 53.78 46.95 9.08 Reasoning LLMs
QwQ-32B DeepSeek-V3.2* BashCoder-R1 (Ours)
58.09 98.84 100.00
56.12 31.28 4.01
R-GRPO directly on the base model (w/o CPT & L-CoT SFT); 3) removing the CPT stage (w/o CPT); and 4) removing the R-GRPO stage (w/o R-GRPO). The results are shown in Table 3. The ablation study demonstrates that each component addresses a distinct challenge in robust Bash generation. CPT provides foundational domain knowledge: removing it (w/o CPT) causes FullRate to drop to 77.36% (single-line) and 64.80% (multi-line) compared to the full model’s 90.04% and 73.18%, as the model lacks essential Bash syntax patterns and command idioms. L-CoT SFT teaches structured reasoning about robustness: using only L-CoT SFT without CPT or R-GRPO (w/o CPT & R-GRPO) results in FullRate of merely 41.14% (single-line) and 24.58% (multi-line) with RobustPass at only 43.21% and 26.26%, showing that reasoning training alone cannot compensate for missing domain knowledge and quality optimization. R-GRPO eliminates remaining code defects through direct optimization: excluding this stage (w/o R-GRPO) leaves FullRate at 63.13% (single-line) and 42.46% (multi-line) with RobustPass at 66.24% and 45.25%, proving that supervised learning alone cannot capture all robustness requirements and reinforcement learning against shellcheck validation is necessary to achieve the full model’s production-grade quality with FullRate of 90.04%/73.18% and RobustPass of 95.99%/79.33%. Together, these three stages form a complete pipeline where CPT builds knowledge, L-CoT SFT develops reasoning capabilities, and R-GRPO refines output quality to match rigorous standards. , Vol. 1, No. 1, Article . Publication date: June 2024.
Towards Robust and Explainable Bash Code Generation with Robustness-Aware Group Relative Policy Optimization 15
Table 2. Performance comparison on BashBench for multi-line script tasks. ↑ indicates higher is better, and ↓ indicates lower is better. * indicates reasoning mode.
Model
SyntaxPass ↑ RWarnRate ↓ RobustPass ↑ FuncRate ↑ FullRate ↑ General LLMs
Qwen2.5-3B-Instruct Qwen2.5-7B-Instruct Qwen2.5-14B-Instruct Qwen2.5-32B-Instruct Qwen3-32B Claude-Sonnet-4.5
90.50 94.97 97.21 92.74 25.14 97.77
85.19 87.06 70.69 76.51 48.89 40.00
13.41 12.29 28.49 21.79 12.85 58.66
87.15 90.50 92.18 89.39 36.31 91.06
11.73 11.17 26.82 20.11 12.85 56.42
11.73 23.46 21.79 12.29 31.84 32.96
39.66 83.80 88.83 91.06 93.30 92.74
11.17 21.23 20.11 11.17 30.17 31.28
12.29 63.13 79.33
48.04 89.39 93.85
11.17 60.89 73.18
Code LLMs CodeLlama-7B-Instruct DeepSeek-Coder-6.7B-Inst Qwen2.5-Coder-3B-Inst Qwen2.5-Coder-7B-Inst Qwen2.5-Coder-14B-Inst Qwen2.5-Coder-32B-Inst
39.11 87.71 92.74 94.97 98.88 97.77
70.00 73.25 76.51 87.06 67.80 66.29 Reasoning LLMs
QwQ-32B DeepSeek-V3.2* BashCoder-R1 (Ours)
48.60 98.88 94.97
74.71 36.16 16.47
Table 3. Ablation study of BashCoder-R1’s training components. Performance (%). w/o: without.
Model Variant Type SyntaxPass ↑ WarnRate ↓ RobustPass ↑ FuncRate ↑ FullRate ↑ w/o CPT & R-GRPO
Single Multi
97.15 93.30
43.94 43.11
54.46 53.07
91.59 90.50
51.88 50.28
w/o CPT & L-CoT SFT
Single Multi
96.64 89.94
55.29 70.81
43.21 26.26
91.33 89.39
41.14 24.58
w/o CPT
Single Multi
98.58 94.41
18.37 28.40
80.47 67.60
92.37 92.74
77.36 64.80
w/o R-GRPO
Single Multi
98.19 93.85
32.54 51.79
66.24 45.25
91.85 90.50
63.13 42.46
Full Model
Single Multi
100.00 94.97
4.01 16.47
95.99 79.33
93.01 93.85
90.04 73.18
Answer to RQ2: The ablation study reveals that CPT, L-CoT SFT, and R-GRPO each contribute uniquely and indispensably to BashCoder-R1’s performance. Removing any component causes substantial degradation across all metrics, confirming that all three stages are necessary to achieve production-grade robust Bash code generation.
, Vol. 1, No. 1, Article . Publication date: June 2024.
16
4.8
Yu et al.
Human Evaluation of Reasoning Chains (RQ3)
To evaluate the quality of the generated reasoning chains, we randomly sampled 150 test cases from BashBench and conducted a blind review comparing BashCoder-R1 against the best-performing baseline (DeepSeek-V3.2 (Reasoning)). The same six experts rated the reasoning chains on a 4point Likert scale (1=Poor, 4=Excellent) across three dimensions: Functionality, Robustness, and Clarity. To ensure reliability, all experts first independently rated a pilot set of 30 samples, achieving substantial inter-rater agreement with Fleiss’ Kappa coefficients of 0.82 for Functionality, 0.79 for Robustness, and 0.86 for Clarity. During formal evaluation, each sample was assigned to one two-person team for independent scoring, with model identities anonymized to eliminate bias. When the two experts’ scores differed by 2 or more points on any dimension, a third expert from another team provided arbitration. DeepSeek-V3.2 (Reasoning) was chosen as the baseline due to its superior performance on both single-line and multi-line tasks in our previous evaluations. Table 4. Human Evaluation of Reasoning Chains, with breakdown for single-line and multi-line tasks. Based on 75 single-line samples and 75 multi-line samples, human experts rated the reasoning chains for different models. The scores are on a 4-point Likert scale (1=Poor, 2=Fair, 3=Good, 4=Excellent). The values represent the number of samples receiving each score. * indicates reasoning mode.
Model
Task Type Dimension 1 (Poor) 2 (Fair) 3 (Good) 4 (Exc.) Functionality Single-line Robustness Clarity
2 5 1
9 21 5
41 35 43
23 14 26
Functionality Robustness Clarity
7 16 5
18 26 11
32 21 36
18 12 23
Functionality Single-line Robustness Clarity BashCoder-R1 (Ours) Functionality Multi-line Robustness Clarity
1 0 0
5 3 2
23 22 25
46 50 48
6 6 3
14 13 9
33 34 32
22 22 31
DeepSeek-V3.2*
Multi-line
As detailed in Table 4, BashCoder-R1 demonstrates superior performance across all dimensions. In terms of Functionality, BashCoder-R1 achieves a high-quality rating (scores 3 or 4) in 82.67% (124/150) of cases, significantly outperforming DeepSeek-V3.2 (Reasoning) at 76.00% (114/150). The most significant advantage is observed in Robustness, where our model receives a highquality rating in 85.33% (128/150) of samples, whereas DeepSeek-V3.2 (Reasoning) lags behind at 56.00% (84/150). This gap is particularly pronounced in single-line commands: BashCoderR1 achieves 96.00% (72/75) high-quality ratings versus only 65.33% (49/75) for DeepSeek-V3.2 (Reasoning), demonstrating superior consideration of edge cases and error handling even in simple commands. For multi-line scripts, BashCoder-R1 maintains consistent advantages with 74.67% (56/75) in Robustness compared to 44.00% (33/75) for DeepSeek-V3.2 (Reasoning). Regarding Clarity, BashCoder-R1 also leads with 90.67% (136/150) of its reasoning chains rated as high-quality, making them easier for developers to audit and trust compared to DeepSeek-V3.2 (Reasoning) at 85.33% , Vol. 1, No. 1, Article . Publication date: June 2024.
Towards Robust and Explainable Bash Code Generation with Robustness-Aware Group Relative Policy Optimization 17
(128/150). These results confirm that the reasoning chains from BashCoder-R1 are not only more aligned with functional and robustness requirements but are also clearer for human developers. Answer to RQ3: The reasoning chains generated by BashCoder-R1 demonstrate superior quality in functionality, robustness, and clarity compared to the strongest reasoning LLM baseline, making them more reliable and trustworthy for developers to use in Bash code generation.
4.9
Case Study (RQ4)
Bash Requirement 1
Bash Requirement 2
Generate a reliable Bash solution with proper syntax and best practices for the given task. Search for files containing specific text pattern and replace it across multiple files with confirmation.
Generate a reliable Bash solution with proper syntax and best practices for the given task. Count the number of lines of code in all source files grouped by file extension.
BashCoder-R1
DeepSeek-V3.2 (Reasoning) #!/usr/bin/env bash set -euo pipefail
<answer> #!/bin/bash
RED='\033[0;31m'; GREEN='\033[0;32m'; NC='\033[0m' print_msg() { echo -e "${1}${2}${NC}"; } ignore_case=false; backup=false; search_dir="." while [[ $# -gt 0 ]]; do case $1 in -d) search_dir="$2"; shift 2 ;; -i) ignore_case=true; shift ;; -b) backup=true; shift ;; *) break ;; esac done
search_pattern="$1" replace_pattern="${2:-}"
search_pattern="${1:-}" replacement_text="${2:-}" [[ -z "$search_pattern" ]] && { print_msg "$RED" "Error: pattern required"; exit 1; } # Build grep options grep_opts="-l" [[ "$ignore_case" == true ]] && grep_opts="$grep_opts -i" file_count=0 while IFS= read -r -d '' file; do if grep -q $grep_opts "$search_pattern" "$file" 2>/dev/null; ⚠ SC2086 ((file_count++)) print_msg "$GREEN" "File $file_count: $file" grep $grep_opts -n "$search_pattern" "$file" | head -3 ⚠ SC2086 if [[ -n "$replacement_text" ]]; then ❌ Undefined variable read -rp "Replace? (y/N): " response Should be: "$replace_pattern" [[ "$response" =~ ^[Yy]$ ]] && { [[ "$backup" == true ]] && cp "$file" "${file}.backup" sed -i "s/$search_pattern/$replacement_text/g" "$file" } ❌ Wrong variable name fi Should be: "$replace_pattern"
fi done < <(find "$search_dir" -type f -print0) echo "Processed: $file_count files"
# Check if search pattern is provided if [ $# -eq 0 ]; then echo "Usage: $0 'search_pattern' [replace_pattern]" exit 1 fi
# Find files containing the search pattern and process them while IFS= read -r -d '' file; do echo "Found in: $file" echo "Content containing '$search_pattern':" ✅ Quoted Properly grep -n "$search_pattern" "$file" if [ -n "$replace_pattern" ]; then read -rp "Replace with '$replace_pattern'? (y/N): " response if [[ "$response" =~ ^[Yy]$ ]]; then sed -i.bak "s/$search_pattern/$replace_pattern/g" "$file" echo "Replacement completed with backup created as ${file}.bak" fi fi echo "---" done < <(grep -rl "$search_pattern" . --null) </answer>
│ BashCoder-R1 ✅ │ ✓ Syntax Test (pass) │ ✓ ShellCheck (pass) │ ✓ Functional Test (pass) │ │ DeepSeek-V3.2 ❌ │ ✓ Syntax Test (pass) │ ✗ ShellCheck (SC2086 × 2) │ ✗ Functional Test (failed)
DeepSeek-V3.2 (Reasoning) #!/usr/bin/env bash set -euo pipefail
BashCoder-R1 <answer> #!/bin/bash
SEARCH_DIR="${1:-.}" EXTENSIONS=( "c" "h" "cpp" "java" "py" "js" "ts" "jsx" "tsx" "go" "rs" "php" "sh" "rb" "swift" "kt" "sql" "html" "css" "xml" "json" "yaml" ) count_lines() { wc -l < "$1" 2>/dev/null | tr -d ' '; } format_num() { printf "%'d" "$1" 2>/dev/null || echo "$1"; } declare -A ext_lines ext_files for ext in "${EXTENSIONS[@]}"; do total=0; count=0 while IFS= read -r -d '' file; do [[ -f "$file" && -r "$file" ]] && { total=$((total + $(count_lines "$file"))) count=$((count + 1)) } done < <(find "$SEARCH_DIR" -type f -name "*.${ext}" -print0 2>/dev/null) [[ $count -gt 0 ]] && { ext_lines["$ext"]=$total ext_files["$ext"]=$count } done echo "Extension Files Lines" for ext in $(printf '%s\n' "${!ext_lines[@]}" | sort); do printf "%-10s %6s %10s\n" ".$ext" \ "$(format_num ${ext_files[$ext]})" \ "$(format_num ${ext_lines[$ext]})" done find "$SEARCH_DIR" -type f 2>/dev/null | sed -n 's/.*\.//p' | \ sort | uniq -c | sort -rn | head -10 | \ while read count ext; do ⚠ SC2162 printf "Other: %-6s %6d files\n" ".$ext" "$count" donedone < <(find "$search_dir" -type f -print0) echo "Processed: $file_count files"
# Count lines of code grouped by file extension find . -type f -exec file {} + | \ grep 'text' | \ while IFS=: read -r filename filetype; do # Get extension ext="${filename##*.}" # Count lines lines=$(wc -l < "$filename" 2>/dev/null || echo 0) echo "$ext $lines" done | \ awk '{sum[$1]+=$2; count[$1]++} END { for (ext in sum) printf "%-10s %6d files %10d lines\n", ext, count[ext], sum[ext] }' | \ sort -k3 -rn </answer>
│ BashCoder-R1 ✅ │ ✓ Syntax Test (pass) │ ✓ ShellCheck (pass) │ ✓ Functional Test (pass) │ │ DeepSeek-V3.2 ❌ │ ✓ Syntax Test (pass) │ ✗ ShellCheck (SC2162 × 1) │ ✓ Functional Test (pass)
Fig. 3. Case Study of Bash Code Generation Using BashCoder-R1.
We demonstrate the effectiveness of BashCoder-R1 in Fig. 3. We specifically select DeepSeek-V3.2 as the comparative baseline because it achieved the highest performance across both single-line (Table 1) and multi-line (Table 2) generation tasks. In the first requirement (search and replace task), DeepSeek-V3.2’s solution contains multiple critical errors. The most severe issue is using an undefined variable $replacement_text instead of the correct $replace_pattern, causing the functional test to fail completely. Additionally, the code has unquoted variable expansions ($grep_opts) that trigger ShellCheck warnings (SC2086 × 2), and the sed command uses unescaped special characters that may cause syntax errors when the pattern contains metacharacters like /, ., or *. Furthermore, there’s a logic inconsistency where the backup condition checks $backup == true, but sed -i.bak always creates a backup file regardless. In contrast, BashCoder-R1 generates syntactically correct code with proper variable quoting, appropriate delimiter usage in sed (s|pattern|replacement|g), and consistent backup logic, successfully passing all functional tests. For the second requirement (line counting by file extension), DeepSeek-V3.2’s solution passes functional tests but receives a ShellCheck warning (SC2162) for missing the -r flag in the , Vol. 1, No. 1, Article . Publication date: June 2024.
18
Yu et al.
read command, which could cause backslash mangling in edge cases. While this is primarily a code quality issue rather than a functional error, it represents suboptimal practice. BashCoderR1 addresses this by using read -r, producing cleaner code that adheres to shell scripting best practices and passes both functional tests and static analysis without warnings. Answer to RQ4: Compared to DeepSeek-V3.2, BashCoder-R1 generates more robust Bash code with proper variable handling, correct syntax, and consistent logic, successfully passing both functional tests and static analysis while DeepSeek-V3.2 produces code with errors and code quality issues.
5
Related Work
5.1 Bash Code Generation from Natural Language Translating natural language instructions into executable Bash commands (NL2Bash) presents significant difficulties. To tackle this, Lin et al. [20] pioneered the field by curating a dataset comprising over 9,000 pairs of Bash code and comments, spanning more than 100 utilities. They benchmarked various models, including Seq2Seq [3, 40], CopyNet [11], and Tellina [20]. More recently, DocCGen [33] enhanced the generation of Domain-Specific Languages (DSLs) from natural language through a two-phase approach. By first retrieving pertinent library documentation and subsequently generating code based on syntax rules, it effectively mitigates syntactic and semantic errors in complex languages like Bash and Ansible YAML. Furthermore, Bridge-Coder [54] focused on generating code for low-resource languages. It introduced the “Code-Bridge” mechanism, which utilizes code-comment pairs from high-resource languages to guide the generation process. 5.2
Bash Code Comment Generation
Regarding the automatic summarization of Bash scripts, Yu et al. [50] developed BASHEXPLAINER. This method employs a dual-stage strategy that first encodes semantics using CodeBERT, then applies information retrieval and deep learning techniques to produce comments based on lexical and semantic similarities. Building on this, Shen et al. [37] presented Bash2Com, which achieves superior performance by incorporating adversarial training and a semantic-aware module. This approach combines semantic representations with a Transformer decoder to yield more precise and fluent descriptions. Most recently, Zhang et al. [55] introduced HBCom, a framework that leverages a Heterogeneous Information Graph (HIG) to synthesize both syntactic and semantic features. 5.3
Reinforcement Learning in LLM Reasoning
Reinforcement Learning (RL) has emerged as a critical frontier for advancing the reasoning capabilities of LLMs [34, 42, 45]. A prominent strategy in this domain is outcome-supervised RL. In this paradigm, models such as DeepSeek-R1 receive rewards based solely on the correctness of their final output, which encourages the development of complex reasoning chains without requiring step-by-step supervision [12]. This method has demonstrated efficacy across a wide array of fields, including software engineering [7, 43, 46], financial analysis [24], computer vision [15, 47], UI automation [27, 28], 3D spatial understanding [32], and tool utilization [17, 18]. Of particular relevance to our work is the success of Group Relative Policy Optimization (GRPO) in generating domain-specific languages. Notable examples include SQL-R1 for Text-to-SQL tasks [29] and SmartCoder-R1 for secure smart contract generation [53]. Drawing inspiration from these breakthroughs, we apply outcome-supervised RL to generate robust and functional Bash scripts. , Vol. 1, No. 1, Article . Publication date: June 2024.
Towards Robust and Explainable Bash Code Generation with Robustness-Aware Group Relative Policy Optimization 19
6
Threats to Validity
Internal Validity: The internal validity of our study hinges on the R-GRPO reward mechanism. While our automated rewards for syntax correctness, robustness (via shellcheck), and format compliance are effective for core objectives, they may not fully capture all nuances of code quality, such as conciseness or stylistic elegance. This could lead BashCoder-R1 to occasionally generate outputs that are functionally correct and robust but overly verbose. While this does not compromise the primary metrics, it represents a potential area for refinement in the reward function design. External Validity: The generalizability of BashCoder-R1’s performance is subject to two main considerations. Our training and evaluation datasets, although comprehensive and curated by experts, represent a subset of the vast and evolving system administration and automation landscape. The model’s performance on highly novel or out-of-distribution scripting tasks or specific operating system environments may vary. 7
Conclusion
In this paper, we introduced BashCoder-R1, a framework designed to generate robust and explainable Bash scripts. Our approach uniquely integrates a three-stage pipeline: Continual Pre-Training to build domain expertise, Long Chain-of-Thought Supervised Fine-Tuning to instill structured robustness reasoning, and Robustness-Aware Group Relative Policy Optimization (R-GRPO) to align the model with rigorous execution standards. Extensive experiments demonstrate that BashCoder-R1 significantly outperforms state-of-the-art baselines in generating code that is not only functionally correct and syntactically valid but also substantially more robust and explainable. 8
Data Availability
All the experimental data and source code is online available at https://zenodo.org/records/18408692 References [1] Miltiadis Allamanis. 2019. The adverse effects of code duplication in machine learning models of code. In Proceedings of the 2019 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software. 143–153. [2] Anthropic. 2025. Introducing Claude Sonnet 4.5. https://www.anthropic.com/news/claude-sonnet-4-5. [3] Kyunghyun Cho, Bart Van Merriënboer, Caglar Gulcehre, Dzmitry Bahdanau, Fethi Bougares, Holger Schwenk, and Yoshua Bengio. 2014. Learning phrase representations using RNN encoder-decoder for statistical machine translation. arXiv preprint arXiv:1406.1078 (2014). [4] Stack Overflow Community. 2025. Newest ’bash’ Questions - Stack Overflow. https://stackoverflow.com/questions/ tagged/bash. [5] Stack Overflow Community. 2025. Newest ’shell’ Questions - Stack Overflow. https://stackoverflow.com/questions/ tagged/shell. [6] Yiwen Dong, Zheyang Li, Yongqiang Tian, Chengnian Sun, Michael W Godfrey, and Meiyappan Nagappan. 2023. Bash in the wild: Language usage, code smells, and bugs. ACM Transactions on Software Engineering and Methodology 32, 1 (2023), 1–22. [7] Lishui Fan, Yu Zhang, Mouxiang Chen, and Zhongxin Liu. 2025. Posterior-GRPO: Rewarding Reasoning Processes in Code Generation. arXiv preprint arXiv:2508.05170 (2025). [8] Quchen Fu, Zhongwei Teng, Marco Georgaklis, Jules White, and Douglas C Schmidt. 2023. Nl2cmd: An updated workflow for natural language to bash commands translation. arXiv preprint arXiv:2302.07845 (2023). [9] Mingyang Geng, Shangwen Wang, Dezun Dong, Haotian Wang, Ge Li, Zhi Jin, Xiaoguang Mao, and Xiangke Liao. 2024. Large language models are few-shot summarizers: Multi-intent comment generation via in-context learning. In Proceedings of the 46th IEEE/ACM International Conference on Software Engineering. 1–13. [10] Aaron Grattafiori, Abhimanyu Dubey, Abhinav Jauhri, Abhinav Pandey, Abhishek Kadian, Ahmad Al-Dahle, Aiesha Letman, Akhil Mathur, Alan Schelten, Alex Vaughan, et al. 2024. The llama 3 herd of models. arXiv preprint arXiv:2407.21783 (2024). [11] Jiatao Gu, Zhengdong Lu, Hang Li, and Victor OK Li. 2016. Incorporating copying mechanism in sequence-to-sequence learning. arXiv preprint arXiv:1603.06393 (2016). , Vol. 1, No. 1, Article . Publication date: June 2024.
20
Yu et al.
[12] Daya Guo, Dejian Yang, Haowei Zhang, Junxiao Song, Ruoyu Zhang, Runxin Xu, Qihao Zhu, Shirong Ma, Peiyi Wang, Xiao Bi, et al. 2025. Deepseek-r1: Incentivizing reasoning capability in llms via reinforcement learning. arXiv preprint arXiv:2501.12948 (2025). [13] Daya Guo, Qihao Zhu, Dejian Yang, Zhenda Xie, Kai Dong, Wentao Zhang, Guanting Chen, Xiao Bi, Yu Wu, YK Li, et al. 2024. DeepSeek-Coder: When the Large Language Model Meets Programming–The Rise of Code Intelligence. arXiv preprint arXiv:2401.14196 (2024). [14] Vidar Holen et al. 2012. ShellCheck: A shell script static analysis tool. (2012). [15] Wenxuan Huang, Bohan Jia, Zijie Zhai, Shaosheng Cao, Zheyu Ye, Fei Zhao, Zhe Xu, Yao Hu, and Shaohui Lin. 2025. Vision-r1: Incentivizing reasoning capability in multimodal large language models. arXiv preprint arXiv:2503.06749 (2025). [16] Binyuan Hui, Jian Yang, Zeyu Cui, Jiaxi Yang, Dayiheng Liu, Lei Zhang, Tianyu Liu, Jiajun Zhang, Bowen Yu, Keming Lu, et al. 2024. Qwen2. 5-coder technical report. arXiv preprint arXiv:2409.12186 (2024). [17] Pengcheng Jiang, Jiacheng Lin, Lang Cao, Runchu Tian, SeongKu Kang, Zifeng Wang, Jimeng Sun, and Jiawei Han. 2025. Deepretrieval: Hacking real search engines and retrievers with large language models via reinforcement learning. arXiv preprint arXiv:2503.00223 (2025). [18] Bowen Jin, Hansi Zeng, Zhenrui Yue, Jinsung Yoon, Sercan Arik, Dong Wang, Hamed Zamani, and Jiawei Han. 2025. Search-r1: Training llms to reason and leverage search engines with reinforcement learning. arXiv preprint arXiv:2503.09516 (2025). [19] Zhiyu Li, Shuai Lu, Daya Guo, Nan Duan, Shailesh Jannu, Grant Jenks, Deep Majumder, Jared Green, Alexey Svyatkovskiy, Shengyu Fu, et al. 2022. Automating code review activities by large-scale pre-training. In Proceedings of the 30th ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering. 1035–1047. [20] Xi Victoria Lin, Chenglong Wang, Deric Pang, Kevin Vu, and Michael D Ernst. 2017. Program synthesis from natural language using recurrent neural networks. University of Washington Department of Computer Science and Engineering, Seattle, WA, USA, Tech. Rep. UW-CSE-17-03 1 (2017), 1–12. [21] Xi Victoria Lin, Chenglong Wang, Luke Zettlemoyer, and Michael D Ernst. 2018. NL2Bash: A Corpus and Semantic Parser for Natural Language Interface to the Linux Operating System. In Proceedings of the Eleventh International Conference on Language Resources and Evaluation (LREC 2018). [22] Aixin Liu, Aoxue Mei, Bangcai Lin, Bing Xue, Bingxuan Wang, Bingzheng Xu, Bochao Wu, Bowei Zhang, Chaofan Lin, Chen Dong, et al. 2025. Deepseek-v3. 2: Pushing the frontier of open large language models. arXiv preprint arXiv:2512.02556 (2025). [23] Fang Liu, Yang Liu, Lin Shi, Houkun Huang, Ruifeng Wang, Zhen Yang, Li Zhang, Zhongqi Li, and Yuchi Ma. 2024. Exploring and evaluating hallucinations in llm-powered code generation. arXiv preprint arXiv:2404.00971 (2024). [24] Zhaowei Liu, Xin Guo, Fangqi Lou, Lingfeng Zeng, Jinyi Niu, Zixuan Wang, Jiajie Xu, Weige Cai, Ziwei Yang, Xueqian Zhao, et al. 2025. Fin-r1: A large language model for financial reasoning through reinforcement learning. arXiv preprint arXiv:2503.16252 (2025). [25] Ilya Loshchilov and Frank Hutter. 2017. Decoupled weight decay regularization. arXiv preprint arXiv:1711.05101 (2017). [26] Junyi Lu, Lei Yu, Xiaojia Li, Li Yang, and Chun Zuo. 2023. Llama-reviewer: Advancing code review automation with large language models through parameter-efficient fine-tuning. In 2023 IEEE 34th International Symposium on Software Reliability Engineering (ISSRE). IEEE, 647–658. [27] Zhengxi Lu, Yuxiang Chai, Yaxuan Guo, Xi Yin, Liang Liu, Hao Wang, Han Xiao, Shuai Ren, Guanjing Xiong, and Hongsheng Li. 2025. UI-R1: Enhancing Efficient Action Prediction of GUI Agents by Reinforcement Learning. arXiv preprint arXiv:2503.21620 (2025). [28] Run Luo, Lu Wang, Wanwei He, and Xiaobo Xia. 2025. Gui-r1: A generalist r1-style vision-language action model for gui agents. arXiv preprint arXiv:2504.10458 (2025). [29] Peixian Ma, Xialie Zhuang, Chengjin Xu, Xuhui Jiang, Ran Chen, and Jian Guo. 2025. Sql-r1: Training natural language to sql reasoning model by reinforcement learning. arXiv preprint arXiv:2504.08600 (2025). [30] Fangwen Mu, Lin Shi, Song Wang, Zhuohao Yu, Binquan Zhang, ChenXue Wang, Shichao Liu, and Qing Wang. 2024. Clarifygpt: A framework for enhancing llm-based code generation via requirements clarification. Proceedings of the ACM on Software Engineering 1, FSE (2024), 2332–2354. [31] Cameron Newham. 2005. Learning the bash shell: Unix shell programming. " O’Reilly Media, Inc.". [32] Zhenyu Pan and Han Liu. 2025. Metaspatial: Reinforcing 3d spatial reasoning in vlms for the metaverse. arXiv preprint arXiv:2503.18470 (2025). [33] Sameer Pimparkhede, Mehant Kammakomati, Srikanth Tamilselvam, Prince Kumar, Ashok Kumar, and Pushpak Bhattacharyya. 2024. DocCGen: Document-based Controlled Code Generation. In Conference on Empirical Methods in Natural Language Processing.
, Vol. 1, No. 1, Article . Publication date: June 2024.
Towards Robust and Explainable Bash Code Generation with Robustness-Aware Group Relative Policy Optimization 21 [34] Aske Plaat, Annie Wong, Suzan Verberne, Joost Broekens, Niki van Stein, and Thomas Back. 2024. Reasoning with large language models, a survey. arXiv preprint arXiv:2407.11511 (2024). [35] Jeff Rasley, Samyam Rajbhandari, Olatunji Ruwase, and Yuxiong He. 2020. Deepspeed: System optimizations enable training deep learning models with over 100 billion parameters. In Proceedings of the 26th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining. 3505–3506. [36] Baptiste Roziere, Jonas Gehring, Fabian Gloeckle, Sten Sootla, Itai Gat, Xiaoqing Ellen Tan, Yossi Adi, Jingyu Liu, Romain Sauvestre, Tal Remez, et al. 2023. Code llama: Open foundation models for code. arXiv preprint arXiv:2308.12950 (2023). [37] Yiheng Shen, Xiaolin Ju, Xiang Chen, and Guang Yang. 2024. Bash comment generation via data augmentation and semantic-aware CodeBERT. Automated Software Engineering 31, 1 (2024), 30. [38] Guangming Sheng, Chi Zhang, Zilingfeng Ye, Xibin Wu, Wang Zhang, Ru Zhang, Yanghua Peng, Haibin Lin, and Chuan Wu. 2025. Hybridflow: A flexible and efficient rlhf framework. In Proceedings of the Twentieth European Conference on Computer Systems. 1279–1297. [39] André Storhaug, Jingyue Li, and Tianyuan Hu. 2023. Efficient avoidance of vulnerabilities in auto-completed smart contract code using vulnerability-constrained decoding. In 2023 IEEE 34th International Symposium on Software Reliability Engineering (ISSRE). IEEE, 683–693. [40] Ilya Sutskever, Oriol Vinyals, and Quoc V Le. 2014. Sequence to sequence learning with neural networks. Advances in neural information processing systems 27 (2014). [41] Qwen Team. 2025. QwQ-32B: Embracing the Power of Reinforcement Learning. https://qwenlm.github.io/blog/qwq32b/. [42] Qineng Wang, Zihao Wang, Ying Su, Hanghang Tong, and Yangqiu Song. 2024. Rethinking the bounds of llm reasoning: Are multi-agent discussions the key? arXiv preprint arXiv:2402.18272 (2024). [43] Sijie Wang, Quanjiang Guo, Kai Zhao, Yawei Zhang, Xin Li, Xiang Li, Siqi Li, Rui She, Shangshu Yu, and Wee Peng Tay. 2025. CodeBoost: Boosting Code LLMs by Squeezing Knowledge from Code Snippets with RL. arXiv preprint arXiv:2508.05242 (2025). [44] Zengzhi Wang, Fan Zhou, Xuefeng Li, and Pengfei Liu. 2025. Octothinker: Mid-training incentivizes reinforcement learning scaling. arXiv preprint arXiv:2506.20512 (2025). [45] Jason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma, Fei Xia, Ed Chi, Quoc V Le, Denny Zhou, et al. 2022. Chain-of-thought prompting elicits reasoning in large language models. Advances in neural information processing systems 35 (2022), 24824–24837. [46] Yuxiang Wei, Olivier Duchenne, Jade Copet, Quentin Carbonneaux, Lingming Zhang, Daniel Fried, Gabriel Synnaeve, Rishabh Singh, and Sida I Wang. 2025. Swe-rl: Advancing llm reasoning via reinforcement learning on open software evolution. arXiv preprint arXiv:2502.18449 (2025). [47] Jiaer Xia, Yuhang Zang, Peng Gao, Yixuan Li, and Kaiyang Zhou. 2025. Visionary-r1: Mitigating shortcuts in visual reasoning with reinforcement learning. arXiv preprint arXiv:2505.14677 (2025). [48] Tian Xie, Zitian Gao, Qingnan Ren, Haoming Luo, Yuqian Hong, Bryan Dai, Joey Zhou, Kai Qiu, Zhirong Wu, and Chong Luo. 2025. Logic-rl: Unleashing llm reasoning with rule-based reinforcement learning. arXiv preprint arXiv:2502.14768 (2025). [49] An Yang, Anfeng Li, Baosong Yang, Beichen Zhang, Binyuan Hui, Bo Zheng, Bowen Yu, Chang Gao, Chengen Huang, Chenxu Lv, et al. 2025. Qwen3 technical report. arXiv preprint arXiv:2505.09388 (2025). [50] Chi Yu, Guang Yang, Xiang Chen, Ke Liu, and Yanlin Zhou. 2022. Bashexplainer: Retrieval-augmented bash code comment generation based on fine-tuned codebert. In 2022 IEEE International Conference on Software Maintenance and Evolution (ICSME). IEEE, 82–93. [51] Lei Yu, Shiqi Chen, Hang Yuan, Peng Wang, Zhirong Huang, Jingyuan Zhang, Chenjie Shen, Fengjun Zhang, Li Yang, and Jiajia Ma. 2024. Smart-LLaMA: two-stage post-training of large language models for smart contract vulnerability detection and explanation. arXiv preprint arXiv:2411.06221 (2024). [52] Lei Yu, Zhirong Huang, Hang Yuan, Shiqi Cheng, Li Yang, Fengjun Zhang, Chenjie Shen, Jiajia Ma, Jingyuan Zhang, Junyi Lu, et al. 2025. Smart-LLaMA-DPO: Reinforced Large Language Model for Explainable Smart Contract Vulnerability Detection. Proceedings of the ACM on Software Engineering 2, ISSTA (2025), 182–205. [53] Lei Yu, Jingyuan Zhang, Xin Wang, Jiajia Ma, Li Yang, and Fengjun Zhang. 2025. Towards Secure and Explainable Smart Contract Generation with Security-Aware Group Relative Policy Optimization. arXiv preprint arXiv:2509.09942 (2025). [54] Jipeng Zhang, Jianshu Zhang, Yuanzhe Li, Renjie Pi, Rui Pan, Runtao Liu, Ziqiang Zheng, and Tong Zhang. 2024. BridgeCoder: Unlocking LLMs’ Potential to Overcome Language Gaps in Low-Resource Code. arXiv preprint arXiv:2410.18957 (2024). [55] Junsan Zhang, Yang Zhu, Ao Lu, Yudie Yan, and Yao Wan. 2025. Bash command comment generation via multi-scale heterogeneous feature fusion. Automated Software Engineering 32, 1 (2025), 28.
, Vol. 1, No. 1, Article . Publication date: June 2024.
22
Yu et al.
[56] Yaowei Zheng, Richong Zhang, Junhao Zhang, Yanhan Ye, and Zheyan Luo. 2024. Llamafactory: Unified efficient fine-tuning of 100+ language models. arXiv preprint arXiv:2403.13372 (2024).
, Vol. 1, No. 1, Article . Publication date: June 2024.