The [..] arithmetic expansion [..]
(c.f. man bash) is available in recent shells only, not in sh..
Arithmetic expansion is part of the POSIX specification. So it depends on what you mean by sh. If it means the classic (non-POSIX) Bourne shell, then yes. If it means a POSIX shell (which is its meaning on almost any POSIX compliant system, /usr/xpg4/bin/sh on Solaris), then no.
This User Gave Thanks to Scrutinizer For This Post:
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
Here is my take on this. Given a modified script:
On my system:
The shell sh is /bin/sh: symbolic link to dash
When we run shellcheck on the script, we get:
So far so good, the warning is correct.
If we then run the script, we get:
So we have fed a syntactically incorrect line into the shell, which has diagnosed it.
If we complain that shellcheck is not diagnosing it, we are on a slippery slope. We would have to re-create the shell mechanism into shellcheck in order to diagnose syntax errors.
The solution, it seems to me, is to get rid of syntax errors, then ask shellcheck to look over the code.
I think we'll all be interested in what the developers say.
Well I got 2 emails back from [koalaman/shellcheck]:-
"""
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub: $(( expression )) error? * Issue #739 * koalaman/shellcheck * GitHub
What is the point of just updating the wiki when it actually does do RED sentences when it is not able to parse a line; after all it is a syntax error...
So in essence it was a waste of time, a lesson learnt for us all...
Hi all...
Been messing around and guess what...
ShellCheck:-
ShellCheck reaults:-
Manually using DASH.
I have posted a report and it is public here so I am off air with this now...
I am well aware of the errors now and this site has a thread on it...
Hello All,
Not sure why this is happening...
When the following If Statement is evaluated for some reason it is creating a file in the CWD called '0'. I've seen this happen
before, just not in an If Statement...
CODE:
if
then
DIR_NAME="$1"
DIR_SIZE=0
STATUS=""
else... (3 Replies)
Hello All,
I'm trying to extract the lines between two consecutive elements of an array from a file.
My array looks like:
problem_arr=(PRS111 PRS213 PRS234)
j=0
while } ]
do
k=`expr $j + 1`
sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt
---some operation goes... (11 Replies)
Hi all,
How am I read a file, find the match regular expression and overwrite to the same files.
open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat";
open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat";
while (<DESTINATION_FILE>)
{
# print... (1 Reply)
CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error.
source $CA_VERSION_DATA
if * ]
then
echo "CA_RELESE $CA_RELEASE is invalid"
exit -1
fi
+ source /etc/ncgl/ca_version_data
++ CA_PRODUCT_ID=samxts
++ CA_RELEASE=6
++ CA_WEEK_NO=7
++... (3 Replies)
#!/bin/bash
if then
#echo "infinite loop"
exit 0
fi
when I run this file I get the following error:
./test_infinite_loop: line 5: syntax error near unexpected token `fi'
./test_infinite_loop: line 5: `fi'
:confused: (4 Replies)
Is it possible to combine a regular expression with a aritmetical expression? For example, taking a 8-numbers caracter sequece and casting each output of a grep, comparing to a constant.
THX! (2 Replies)