bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

An alias named `done` breaks for loops


From: George Nachman
Subject: An alias named `done` breaks for loops
Date: Sat, 14 Aug 2021 15:59:38 -0700

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: darwin20.5.0
Compiler: gcc
Compilation CFLAGS: -g -O2 -Wno-parentheses -Wno-format-security
uname output: Darwin Georges-Mac-Pro.local 20.5.0 Darwin Kernel Version
20.5.0: Sat May  8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64
x86_64
Machine Type: x86_64-apple-darwin20.5.0

Bash Version: 5.1
Patch Level: 8
Release Status: release

Description:
Defining an alias named `done` breaks parsing a for loop that does not have
an `in word` clause.


Repeat-By:

Run the following script. It fails with this error:

myscript.bash: line 7: syntax error near unexpected token `done'
myscript.bash: line 7: `  done'


#!/bin/bash

alias done=""

f() {
  for var; do
  done
}


Fix:
`done` should not be considered a simple command in the context where it
would terminate a for loop. Alternately, prevent the user from creating
aliases that will cause problems like this.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]