[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
`declare -f "a="' fails unnecessarily
From: |
Emanuele Torre |
Subject: |
`declare -f "a="' fails unnecessarily |
Date: |
Sat, 3 Dec 2022 12:18:16 +0100 |
`declare -f "something="' fails with the following error:
$ declare -f 'a=x'
bash: declare: cannot use `-f' to make functions
$ f=a=x
$ decalre -f -- "$f"
bash: declare: cannot use `-f' to make functions
That error is not very useful. Bash makes `declare -f' fail with that
error when an argument looks like an assignment.
Since, in Bash, it is permitted to define functions that have names that
look like an assignments, I think it would make more sense if it would
just look for that function, instead of failing unnecessarily.
$ function axb { printf hi\\n; }
$ function a=b { printf hi\\n; }
$ if declare -f 'axc' > /dev/null; then echo defined; else echo undefined;fi
defined
$ if declare -f 'abc' > /dev/null; then echo defined; else echo undefined;fi
undefined
$ if declare -f 'a=c' > /dev/null; then echo defined; else echo undefined;fi
bash: declare: cannot use `-f' to make functions
undefined
$ if declare -f 'a=b' > /dev/null; then echo defined; else echo undefined;fi
bash: declare: cannot use `-f' to make functions
undefined
emanuele6
- `declare -f "a="' fails unnecessarily,
Emanuele Torre <=