For loop after upgrading


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For loop after upgrading
# 1  
Old 08-13-2016
For loop after upgrading

Hello everybody,

I upgraded from Ubuntu 12.04 to 14.04, so some of my scripts in bash does NOT work, for example:

Code:
#!/bin/bash

# Some codes goes here


        for ((offset=$thumbStart; offset<=$thumbEnd; offset+=10)) # LINE 459
        do
        printf -v outfile "$filePNG"_"%03d.png" "$((++n))"

        ffmpeg -itsoffset -$offset -i $fileFinal -vcodec mjpeg -vframes 1 -an -f rawvideo -s 640x480 "$outfile"

        done

        mv *.png $path2thumb

         fi # End if [ $thumb -eq 0 ]

        multipleThumbs=$?

        } # end multipleThumbs

output is:

Code:
# sh runScript.sh 
smartCode.sh: 459: functions.sh: Syntax error: Bad for loop variable

Thanks in advance
# 2  
Old 08-13-2016
It would appear that the new version of bash that you are now running has an additional keyword that you can no longer use as a variable name in your scripts. Try changing:
Code:
        for ((offset=$thumbStart; offset<=$thumbEnd; offset+=10)) # LINE 459
        do
        printf -v outfile "$filePNG"_"%03d.png" "$((++n))"

        ffmpeg -itsoffset -$offset -i $fileFinal -vcodec mjpeg -vframes 1 -an -f rawvideo -s 640x480 "$outfile"

to:
Code:
        for ((Offset=$thumbStart; Offset<=$thumbEnd; Offset+=10)) # LINE 459
        do
        printf -v outfile "$filePNG"_"%03d.png" "$((++n))"

        ffmpeg -itsoffset -$Offset -i $fileFinal -vcodec jpeg -vframes 1 -an -f rawvideo -s 640x480 "$outfile"

and see if that works.
# 3  
Old 08-13-2016
I tried your example, I've got the same error, so I made another example:

Code:
#!/bin/bash

for (( i=0; i<=10; i+=2 ))
do
 echo "Welcome $i times" 
done

then

Code:
sh.sh: 3: sh.sh: Syntax error: Bad for loop variable

# 4  
Old 08-13-2016
It would be interesting to know what version of bash you are actually using as I can only create that error in " dash ".
bash -version
Code:
Last login: Sat Aug 13 12:31:55 on ttys000
AMIGA:barrywalker~> dash
AMIGA:\u\w> #!/bin/bash

for (( i=0; i<=10; i+=2 ))
do
 echo "Welcome $i times" 
doneAMIGA:\u\w> AMIGA:\u\w> dash: 3: Syntax error: Bad for loop variable
AMIGA:\u\w> dash: 3: Syntax error: "do" unexpected
AMIGA:\u\w> AMIGA:\u\w> Welcome  times
AMIGA:\u\w> exit
dash: 5: doneexit: not found
AMIGA:\u\w> exit
AMIGA:barrywalker~> 
AMIGA:barrywalker~> #!/bin/bash
AMIGA:barrywalker~> 
AMIGA:barrywalker~> for (( i=0; i<=10; i+=2 ))
> do
>  echo "Welcome $i times" 
> done
Welcome 0 times
Welcome 2 times
Welcome 4 times
Welcome 6 times
Welcome 8 times
Welcome 10 times
AMIGA:barrywalker~> _

This User Gave Thanks to wisecracker For This Post:
# 5  
Old 08-13-2016
Here you go

Code:
# bash -version
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

# 6  
Old 08-13-2016
Hi.
Quote:
Originally Posted by Abu Rayane
...
Code:
sh.sh: 3: sh.sh: Syntax error: Bad for loop variable

Because of the sh.sh, it looks to me like there is an alias for bash, or sh.sh is named bash in /bin

Thsi code worked for me in:
Code:
OS, ker|rel, machine: Linux, 3.16.0-73-generic, x86_64
Distribution        : Ubuntu 14.04.2 (KDE, Trusty Tahr) 
bash GNU bash 4.3.11

as well as in:
Code:
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.4 (jessie) 
bash GNU bash 4.3.30

Best wishes ... cheers, drl
# 7  
Old 08-13-2016
It seems something strange with it:

Code:
# mv sh.sh test.sh
# sh test.sh 
test.sh: 3: test.sh: Syntax error: Bad for loop variable

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Problem Upgrading OS

Hi I've just upgraded OS - using "Migration with nimadm". The Nim master is a Power 6 server, and the source is 6100-09-04-1441. The migration was successful with a Power 6 - Nim client, but there was a problem with Power 5 - Nim client : the OS remained 6100-00-09-0920 icapp1:/]oslevel -s... (1 Reply)
Discussion started by: bobochacha29
1 Replies

2. AIX

Upgrading PowerHA from 7.1.0 to 7.1.3

Hi All, As per the IBM upgrade/support matrix IBM Techdocs Technote: PowerHA for AIX Version Compatibility Matrix we can't do online upgrade or rolling migration from powerha v7.1.0 to v7.1.3. on AIX61_TL9_SP4, So we are following the steps as below ... 1 ) Bring down the cluster 2 )... (2 Replies)
Discussion started by: linux.amrit
2 Replies

3. AIX

Upgrading OS from 5.2 to 5.3

We currently have test and production servers running AIX 5.2, DB2 8.1(Prod), DB2 8.2(Test),Websphere 6.1 on both. We need to upgrade to DB2 to version 9, but to do that we also need to upgrade the operating system to 5.3 and go from 32 bit kernel to 64 bit kernal. Looking for information on any... (3 Replies)
Discussion started by: jyoung
3 Replies

4. BSD

Upgrading to FreeBSd 7.1

I have installed Free BSD 7.1 an would like to upgrade to 8.0 using theupgrade option under sysinstall. Is this posible? (3 Replies)
Discussion started by: FloridaBSD
3 Replies

5. Solaris

OS_LDAP upgrading

Hi All, We are going to upgrading Solaris-5.8 to Solaris 5.10, as well as LDAP 5.1 service pack-3 to LDAP 5.1 service pack-4, So I'm requesting to all what is the best way to upgrade Solaris-5.8, LDAP 5.1 service pack-3 to LDAP 5.1 service pack-4 in solaris-5.10, As per my knowledge there... (1 Reply)
Discussion started by: mkanuri
1 Replies

6. Filesystems, Disks and Memory

Upgrading PC Memory

hello folks, I am planning to upgrade my PC's ram. currently the ram I have is 2x256MB=512MB/133MHz (DDR266) - DDR SDRAM, PC-2100. My guess is that it has 184 Pins. I would like to get a DDR2 with 667MHz, 240 pin. Is it possible, since pins don't match. Do they have to match? (there are 3... (4 Replies)
Discussion started by: milhan
4 Replies

7. AIX

Upgrading from 5.1.0.0 to 5.2.0.0

As a fairly new Administrator to AIX i am a little leary of the OS upgrade I need to do on one of our servers. I have already upgraded the microcode to the lastest level and now need to do the OS. I have the docs and discs from IBM and have determined that I dont want to do a new installation but... (5 Replies)
Discussion started by: Target
5 Replies

8. Solaris

upgrading to solaris 9

Hey All We are having ORacle 8.1.7 and ORacle 9.2.0.4 installed in our Sun sparc Servers(oON SOLARIS 8). We are going to upgrade our servers to SOLARIS Ver 9 Solaris ver 9 supports the above mentioned Oracle versions. Can any one help me out how to upgrade from solaris 8 to solaris 9. ... (2 Replies)
Discussion started by: solaris8in
2 Replies

9. UNIX for Dummies Questions & Answers

Upgrading to PHP 4.3.4 from 4.2.2

ok im trying to upgrade but i keep geting an error and 1 says it ned the other to install but nethere will install heres what im getting now though now i have 4.2.2-17.2 installed now do i have to unintall everything to get this to install or how do i go about it thank you for your help (3 Replies)
Discussion started by: Blackrose
3 Replies
Login or Register to Ask a Question