You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

POSIX Shell脚本意外退出问题排查求助

Hey there! Let's break down this tricky shell script issue you're dealing with— that "coordinates must be in pairs" error is a clear sign something's misfiring with how your mouse_click_coords() function gets its arguments, and it's yanking your script to a halt before it can finish its work. Here's how to debug and fix it:

1. Start with the error's source: mouse_click_coords()

First, track down the definition of this function in your script. The error message tells us it expects coordinate pairs (like x1 y1 x2 y2), so it’s probably checking that the number of arguments is even, or that at least two values are passed. Look for logic like:

mouse_click_coords() {
    if [ $# -eq 0 ] || [ $(( $# % 2 )) -ne 0 ]; then
        echo "mouse_click_coords(): Coordinates must be in pairs! Exit code = 14" >&2
        exit 14
    fi
    # rest of the function...
}

This check is failing somewhere, so we need to find where the function is being called with bad arguments.

2. Trace the function call in your first loop

Since the script dies right after the first loop, focus on the mouse_click_coords() call inside that loop. Ask yourself:

  • How are the coordinates being generated? Are they pulled from a variable, command output, or command-line argument?
  • Did you accidentally remove a parameter in a recent edit? For example, changing mouse_click_coords "$x" "$y" to mouse_click_coords "$x" would trigger this error.
  • Is a variable holding a coordinate empty? If $y is unset or blank, POSIX shell will drop it when passing arguments, turning a pair into a single value.
3. Add debug prints to catch bad arguments

When you can’t remember what you changed, debug logs are your best friend. Add these lines to see exactly what’s being passed to the function:

  • Right before calling mouse_click_coords() in the loop:
    echo "DEBUG: Calling mouse_click_coords with args: $# total | $*" >&2
    mouse_click_coords "$@"
    
  • Or at the very start of the mouse_click_coords() function:
    mouse_click_coords() {
        echo "DEBUG: mouse_click_coords received: $# arguments | $*" >&2
        # original validation logic here
    }
    

Run your script again, and the debug output will show you exactly which call has an odd number of arguments, or missing values.

4. Double-check the -1 option handling

Even though both launch modes fail the same way, confirm the -1 option isn’t messing with coordinate generation:

  • Look for your script’s argument-parsing logic (likely using while getopts). Does handling -1 modify variables that the loop uses to generate coordinates? For example, overwriting a variable that stores Y-values, or changing how many iterations the loop runs?
  • It’s possible a recent edit broke the option handling in a way that affects both modes (e.g., a misplaced shift that eats a coordinate argument).
5. Compare with a working version (if possible)

If you use version control like git, compare your current script to the last known working version. Focus on:

  • Changes to mouse_click_coords() or its calls
  • Edits to the first loop’s logic
  • Modifications to command-line argument parsing

A quick git diff will highlight exactly what you changed that might have caused the breakage.

Pro Tip for POSIX Shell Safety

Always wrap variables in double quotes when passing them as arguments (e.g., "$x" instead of $x). If a variable has spaces or special characters, skipping quotes will split it into multiple arguments, which can easily turn coordinate pairs into an odd number of values.

内容的提问来源于stack exchange,提问作者Vlastimil Burián

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:08:23