Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variable is assigned a string and later it is used as an array #1534

Open
3 of 4 tasks
ycdtosa opened this issue Mar 25, 2019 · 1 comment
Open
3 of 4 tasks

variable is assigned a string and later it is used as an array #1534

ycdtosa opened this issue Mar 25, 2019 · 1 comment

Comments

@ycdtosa
Copy link

ycdtosa commented Mar 25, 2019

For bugs

  • Rule Id (if any, e.g. SC1000):

  • My shellcheck version (shellcheck --version or 'online'): online
    (but also tested with version 0.4.4 on debian)

  • I tried on shellcheck.net and verified that this is still a problem on the latest commit

  • It's not reproducible on shellcheck.net, but I think that's because it's an OS, configuration or encoding issue

For new checks and feature suggestions

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

#!/bin/bash
readonly Array=" --parameter=value --another=12 "
echo "${Array[@]}"

Here's what shellcheck currently says:


Here's what I wanted or expected to see:

Line 3	SCXXXX: variable used as an array but it was previosly assigned a string.

Note: The purpose of my real code is other than echo.

The description of the issue should say how to fix the code:

#!/bin/bash
readonly Array=( --parameter=value --another=12 )
echo "${Array[@]}"

I though this issue might be related, but it was fixed long ago #102

This is kind of the opposite of SC2178

@ycdtosa ycdtosa changed the title TODO: Add title variable is assigned a string but is used as an array Mar 25, 2019
@ycdtosa ycdtosa changed the title variable is assigned a string but is used as an array variable is assigned a string and later it is used as an array Mar 26, 2019
@Crestwave
Copy link

Note that a legitimate use of this is to make it expand to nothing if the variable is unset, as opposed to an empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants