koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
36.1k stars 1.76k forks source link

shellcheck not detecting bad substitution in dash and bash when using ${#$var} #847

Open nihilus opened 7 years ago

nihilus commented 7 years ago

For new checks and feature suggestions

Here's a snippet or screenshot that shows the problem:


#!/bin/sh
var="foo"
echo "${#$var}"

Here's what shellcheck currently says:

No issues detected!

Here's what I wanted or expected to see:

Something about 'bad substitution'.

mmlb commented 7 years ago

@nihilus just fyi that a tool I use along with shellcheck catches this, might want to add to the belt.

cat <<'EOF' | shfmt                                                                                                     
var="foo"
echo "${#$var}"
EOF
2:11: $ cannot be followed by a word 
nihilus commented 7 years ago

@mmlb nice tool, I integrated it today as part of our buildprocess.