skip to Main Content

I was running a script and got the error: ./run.sh: line 21: $1: unbound variable

Here it is

# Make sure we have something to run
**if [ "$1" = "" ]; then
**    log "Usage: $0 program [args]"
    exit 1
fi

Any help would be greatly appreciated!

I didn’t write the code and I have no experience, so I don’t even know where to start.

2

Answers


  1. Remove set -u (short syntax) or set -o nounset (long syntax) from your not shown code.

    From help set:

    -u: Treat unset variables as an error when substituting.

    Login or Signup to reply.
  2. If you didn’t write the script and have no intentions of fixing it, assume it’s not handling the errors in a great way and, in this case, just provide the argument expected (which perhaps you know)

    ./run.sh whatever
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search