bad interpreter when running script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bad interpreter when running script
# 8  
Old 03-09-2011
Code:
#!/bin/sh

# This would run the loop exactly once, with i="/opt/product/arsystem/test/".
# for i in /opt/product/arsystem/test/    

# I think you meant this, to match all files in that dir
for i in /opt/product/arsystem/test/*
do
    # just a sanity check.  Don't run file on directories.
    [ -d "$i" ] && continue
    # newline here
    file "$i"  
    x=${i##*.}
    # wrong kind of brackets, and you missed one '
    # z=${perl -e 'print time;}
    z=$(perl -e 'print time')
    r=LicenseReport.txt.$x    
     t=$(echo $z-$x|bc)    
    if ((t>86400))
    then
        # newline here
        tar -cvf $r.tar $r
    
        echo $i;
         echo $z; 
         echo $x;
         echo $t; 
         echo $r;
    else
        # can't leave a branch empty.
        # Use : whenever you need to do nothing.
        :
    fi
done

There's all kinds of ways to optimize this script too, if you're interested. Lots of unnecessary calls to perl and bc can be streamlined.

You're also using some shell-specific things like the double bracket (( )) operator. If you want to use these, you should make the first line #!/bin/bash or #!/bin/ksh (depending on which you're using) so the script doesn't mysteriously break down when you move it to another system.
# 9  
Old 03-09-2011
Not sure this line is syntaxically correct:
Code:
z=${perl -e 'print time;}

Maybe you meant this ?
Code:
z=$(perl -e 'print time')


Last edited by Dahu; 03-09-2011 at 01:18 PM.. Reason: Corona688 was quicker ...
# 10  
Old 03-10-2011
That's I wrote, fi after done work's better, but we still have error :
Code:
 - ./script.sh: erreur de syntaxe ligne 18: `t=$' inattendue
 - ./script.sh: syntax error line 18: `t=$' unexpected.

I working on it

Regards Smilie

--------------------------------------------------------------------------

Code:
#!/bin/sh

# This would run the loop exactly once, with i="/opt/product/arsystem/test/".
# for i in /opt/product/arsystem/test/    

# I think you meant this, to match all files in that dir
for i in /opt/product/arsystem/test/*
do
    # just a sanity check.  Don't run file on directories.
    #[ -d "$i" ] && continue
    # newline here
    file "$i"  
    x=${i##*.}
    # wrong kind of brackets, and you missed one '
    z=${perl -e 'print time'}
    # z=$(perl -e 'print time')
    r=LicenseReport.txt.$x    
    t=$(echo $z-$x|bc)    
    if ((t>86400))
    then
        # newline here
        tar -cvf $r.tar $r
    
        echo $i;
         echo $z; 
         echo $x;
         echo $t; 
         echo $r;
    else
        # can't leave a branch empty.
        # Use : whenever you need to do nothing.
        :
    done    
    fi

---------- Post updated at 04:41 AM ---------- Previous update was at 04:09 AM ----------

With the script below we have the error :

Code:
/opt/product/arsystem/test/LicenseReport.txt.1298111407:        commandes
./script.sh: substitution incorrecte (bad substitution)

Code:
#!/bin/sh

# This would run the loop exactly once, with i="/opt/product/arsystem/test/".
# for i in /opt/product/arsystem/test/    

# I think you meant this, to match all files in that dir
for i in /opt/product/arsystem/test/*
do
    # just a sanity check.  Don't run file on directories.
    [ -d "$i" ] && continue
    # newline here
    file "$i"  
    x=${i##*.}
        echo $i;
         echo $z; 
         echo $x;
         echo $t; 
         echo $r;
    # wrong kind of brackets, and you missed one '
    z=${perl -e 'print time'}
    # z=$(perl -e 'print time')
    r=LicenseReport.txt.$x    
    t=${echo $z-$x|bc}    
    if [ "$t" -gt "86400" ]
    then
        # newline here
        tar -cvf $r.tar $r
    

    else
        # can't leave a branch empty.
        # Use : whenever you need to do nothing.
        :
    fi    
   done

---------- Post updated at 05:01 AM ---------- Previous update was at 04:41 AM ----------

Find something wrong, I put echo $i before x=${i##*.}, then he show me the value of i like that :
Code:
/opt/product/arsystem/test/LicenseReport.txt.1298111407


Last edited by Franklin52; 03-10-2011 at 06:24 AM.. Reason: Please use code tags
# 11  
Old 03-10-2011
Code:
#!/bin/sh
for i in /opt/product/arsystem/test/*
do
    # just a sanity check.  Don't run file on directories.
    [ -d "$i" ] && continue
    # newline here
    file "$i"
    x=${i##*.}
        echo $i;
         echo $z;
         echo $x;
         echo $t;
         echo $r;
    z=$(perl -e 'print time')
    r=LicenseReport.txt.$x
    t=$(echo $z-$x|bc)
    if [ "$t" -gt "86400" ]
    then
        # newline here
        tar -cvf $r.tar /opt/product/arsystem/test/$r
    fi
   done

I've simplified the code and made some arrangements:
For the first two red lines, you needed to use parenthesis and not brackets (brackets are for variable substitution)
The third red line is here because the tar command need to have correct paths in order to behave properly. The error you'll have in this case is :
Code:
tar: LicenseReport.txt.1298111407: Cannot stat: No such file or directory

# 12  
Old 03-10-2011
Quote:
Originally Posted by bzb23
# wrong kind of brackets, and you missed one '
z=${perl -e 'print time'}
You copied the comment telling you you had the wrong brackets, but still didn't use the right brackets... Smilie Maybe {} and () look extremely similar in some fonts. The brackets for variable names are shift-[ and shift-], the brackets for enclosing statements are shift-9 and shift-0.
# 13  
Old 03-10-2011
Quote:
Originally Posted by Corona688
The brackets for variable names are shift-[ and shift-], the brackets for enclosing statements are shift-9 and shift-0.
If you have an AZERTY keyboard, the bracket and parenthesis are done with different keystrokes Smilie
AltGr-4 for {
AltGr-+ for }
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

-bash: ./p4: /bin/ksh^M: bad interpreter: No such file or directory

I keep getting this error and I am not sure why. -bash: ./p4: /bin/ksh^M: bad interpreter: No such file or directory First I run my makefile and this works fine: goodmain: main.o gcc -o goodmain main.o main.o: main.c gcc -c main.c Then I want to limit my output so I... (11 Replies)
Discussion started by: cokedude
11 Replies

2. UNIX for Advanced & Expert Users

Sqlite3: /lib/ld-Linux.so.2: bad ELF interpreter:

Hi all I'm hoping this is just me being a muppet, has anyone come across this problem before? I am writing an application that uses sqlite3 and I have created a database using it - sqlite3 muse.db SQLite version 3.6.20 Enter ".help" for instructions Enter SQL statements terminated with... (2 Replies)
Discussion started by: steadyonabix
2 Replies

3. Red Hat

Not able to run any command /lib64/ld-Linux-x86-64.so.2: bad ELF interpreter

Hi, I accidentally did this: wadhwaso@nxsdgd01 deps]$sudo rpm -e --nodeps glibc-2.5-107.x86_64 error: %postun(glibc-2.5-107.x86_64) scriptlet failed, exit status 255 and since then I am not able to run any command on this server except 'cd'. I always get the following error: $ ls... (6 Replies)
Discussion started by: stunn3r
6 Replies

4. Shell Programming and Scripting

Bad Interpreter

Hi. My name is Caleb (a.k.a RagingNinja) form the whited00r forums. (Whited00r makes custom firmware for iOS devices). I have been learning and creating simple shells scripts. I have been recently using VIM for Windows or using VirtualBox to run the UBUNTU OS within VirtualBox to create my shell... (2 Replies)
Discussion started by: RagingNinja
2 Replies

5. Shell Programming and Scripting

bad interpreter: Permission denied

Hi I am running a script: #!bin/bash set -x echo"select * from celldatamap;" || sqlcsv -v -h -s ',' -d MTNSA11G -u datasafe -p datasafe > andrea.csv When I run my script ./tablescript.sh I get the following error: $ ./tablescript.sh (3 Replies)
Discussion started by: ladyAnne
3 Replies

6. Shell Programming and Scripting

Executing expect script giving message as bad interpreter: Permission denied

Hi Gurus, I am new to scripting and needs your help in expect script used for telnet. I wrote a simple script as #!/usr/bin/expect-5.43 -f spawn telnet localhost 2233 expect "password:" send "secret\r" send "i data.cnbc.com\r" send "exit\r" expect eof When I am trying to execute... (2 Replies)
Discussion started by: niks_yv
2 Replies

7. Shell Programming and Scripting

Perl - bad interpreter: No such file or directory

Here is a puzzler. To start, let me say that I've done a search on this issue and it is definitely not related to line endings being encoded in windows returns. I get this error when I run SOME perl scripts. I have a script called hello_world.pl. I do $cp hello_world.pl new_hello_world.pl... (0 Replies)
Discussion started by: mjmtaiwan
0 Replies

8. Ubuntu

How to resolve bad interpreter error

Hi, Iam trying to run a gmake command and have the latest version of Gnu in my redhat linux system. I need to execute the following steps; ---> chmod +x utils/* ---> ./utils/AllCodeManagerFix ---> gmake LINUX Iam able to do the chmod command but when I run the second command I get... (2 Replies)
Discussion started by: viji19812001
2 Replies

9. UNIX for Dummies Questions & Answers

bad interpreter: Permission denied

I am writing an expect script but am getting a bad interpreter: permission denied error. I don't think the error has anything to do with expect itself, I think I am missing something in how I start the file. For instance, when I run the file under the expect directory it works: cd... (7 Replies)
Discussion started by: earnstaf
7 Replies

10. Shell Programming and Scripting

/bin/sh: bad interpreter: Permission denied

today i started the LFS book (version 4.0). Basically i am using slackware 9.0 to try and install a new linux completely from source on another partition. Now i took the book's recommendations and created a user called lfs so i wouldn't have to do the stuff as root, and i have got the new LFS... (4 Replies)
Discussion started by: Calum
4 Replies
Login or Register to Ask a Question