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

Syntax error in redirection is not identified #3157

Open
lijh8 opened this issue Mar 10, 2025 · 0 comments
Open

Syntax error in redirection is not identified #3157

lijh8 opened this issue Mar 10, 2025 · 0 comments

Comments

@lijh8
Copy link

lijh8 commented Mar 10, 2025

Hi,

Syntax error in redirection is not identified.

$ cat hello.sh 
#!/bin/bash

shopt -s expand_aliases
alias echo='echo "$BASH_SOURCE:$LINENO:$FUNCNAME:"'

main1() {
        local a b c d

        a=20
        b=30
        c=`expr $a + $b 2 > /dev/null` # should be 2>
        d=$?
        test $d -eq 0 -o $d -eq 1 && echo "$c" || echo "error: $a + $b"
}

main1
$ 

$ shellcheck hello.sh; bash hello.sh; 

In hello.sh line 11:
        c=`expr $a + $b 2 > /dev/null` # should be 2>
          ^--------------------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`.
           ^--^ SC2003 (style): expr is antiquated. Consider rewriting this using $((..)), ${} or [[ ]].

Did you mean: 
        c=$(expr $a + $b 2 > /dev/null) # should be 2>

For more information:
  https://www.shellcheck.net/wiki/SC2003 -- expr is antiquated. Consider rewr...
  https://www.shellcheck.net/wiki/SC2006 -- Use $(...) notation instead of le...
expr: syntax error: unexpected argument ‘2’
hello.sh:13:main1: error: 20 + 30
$ 

$ cat /etc/os-release | grep PRETTY_NAME
PRETTY_NAME="Debian GNU/Linux trixie/sid"
$ 

$ shellcheck --version
ShellCheck - shell script analysis tool
version: 0.10.0
license: GNU General Public License, version 3
website: https://www.shellcheck.net
$ 
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

1 participant