SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
Fix tools unbound variable errors
carlosejimenez7f02e50344d4
diff --git a/tools/defaults/bin/create b/tools/defaults/bin/createindex 3df63e90..92abc456 100644--- a/tools/defaults/bin/create+++ b/tools/defaults/bin/create@@ -3,22 +3,23 @@ set -euo pipefailsource /root/tools/defaults/lib/utils.shmain() {- if [ -z "$1" ]; then+ local filename="${1:-}"+ if [ -z "${filename}" ]; thenecho "Usage: create <filename>"exit 1fi# Check if the file already exists- if [ -e "$1" ]; then- echo "Error: File '$1' already exists."- open "$1" || exit 1+ if [ -e "${filename}" ]; then+ echo "Error: File '${filename}' already exists."+ open "${filename}" || exit 1exit 1fi# Create the file an empty new line- printf "\n" > "$1"+ printf "\n" > "${filename}"# Use the existing open command to open the created file- open "$1" || exit 1+ open "${filename}" || exit 1}main "$@"diff --git a/tools/defaults/bin/open b/tools/defaults/bin/openindex a8b0d198..f8c4dbcb 100644--- a/tools/defaults/bin/open+++ b/tools/defaults/bin/open@@ -5,8 +5,7 @@ source /root/tools/defaults/lib/utils.shmain() {local WINDOW=$(_read_env WINDOW)- if [ -z "$1" ]- then+ if [ $# -eq 0 ]; thenecho "Usage: open \"<file>\""exit 1fi@@ -19,7 +18,7 @@ main() {fi# Check if the second argument is provided- if [ -n "$2" ]; then+ if [ $# -ge 2 ]; then# Check if the provided argument is a valid numberif ! [[ $2 =~ ^[0-9]+$ ]]; thenecho "Usage: open \"<file>\" [<line_number>]"diff --git a/tools/edit_linting/bin/edit b/tools/edit_linting/bin/editindex 6defeec3..778994d9 100644--- a/tools/edit_linting/bin/edit+++ b/tools/edit_linting/bin/edit@@ -12,6 +12,13 @@ main() {returnfi+ if [ $# -eq 0 ]; then+ echo "Usage: edit <start_line>:<end_line>"+ echo "<replacement_text>"+ echo "end_of_edit"+ return+ fi+local start_line="$(echo $1: | cut -d: -f1)"local end_line="$(echo $1: | cut -d: -f2)"diff --git a/tools/search/bin/search_file b/tools/search/bin/search_fileindex 4c6828f2..4a942b1e 100644--- a/tools/search/bin/search_file+++ b/tools/search/bin/search_file@@ -2,12 +2,13 @@ source /root/tools/defaults/lib/utils.shmain() {# Check if the first argument is provided- if [ -z "$1" ]; then+ local search_term="${1:-}"+ if [ -z "${search_term}" ]; thenecho "Usage: search_file <search_term> [<file>]"returnfi# Check if the second argument is provided- if [ -n "$2" ]; then+ if [ $# -ge 2 ]; then# Check if the provided argument is a valid fileif [ -f "$2" ]; thenlocal file="$2" # Set file if valid@@ -18,7 +19,7 @@ main() {fielse# Check if a file is open- if [ -z "$CURRENT_FILE" ]; then+ if [ -z "${CURRENT_FILE:-}" ]; thenecho "No file open. Use the open command first."return # Exit if no file is openfi@@ -29,7 +30,7 @@ main() {# Use grep to directly get the desired formatted outputlocal matches=$(grep -nH -- "$search_term" "$file")# Check if no matches were found- if [ -z "$matches" ]; then+ if [ -z "${matches:-}" ]; thenecho "No matches found for \"$search_term\" in $file"returnfi