shell scripting error help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell scripting error help
# 1  
Old 05-16-2010
MySQL shell scripting error help

Im tryign to write a script that counts the number of new lines in the file with the most new lines in a given directory

i keep getting this error


/export/home/sieben01/itec400/homework> ./maxlines.sh
./maxlines.sh[12]: syntax error: `then' unexpected operator/operand

any ideas?


Code:
#!/bin/ksh

ERROR1="error:can only use 0 or 1 arguments.\nusage:maxlines.sh[directory]"
ERROR2="error:argument must be a Directory.\nusage:maxlines.sh[directory]\n"
if [[ $# -gt 1 ]]
  then
        printf "$ERROR1"
        exit 1
fi
DIR="."
if [[ $# -eq 1]]
   then
        if[[ -d $1 ]]
        then
        DIR="$1"
   else
        printf "$ERROR2"
        exit 1
fi
cd $DIR
FILE=$(wc-l `ls` 2>/dev/null | sort -bn | Tail -n 2 | head -n 1)
printf "File `echo $FILE | awk '{print $2}'` has the maximum lines with `echo $1| awk '{print $1}'` lines.\n"
exit 0

# 2  
Old 05-16-2010
You are missing a 'fi' in your nested if statement.
# 3  
Old 05-16-2010
Quote:
Originally Posted by bluescreen
You are missing a 'fi' in your nested if statement.
thanks. fixed that. still getting same error though
# 4  
Old 05-16-2010
Code:
if [[ $# -eq 1 ]]   <<----  space after "1"
   then
        if [[ -d $1 ]]  <<---- space after "if"

# 5  
Old 05-16-2010
there's a typo in your inner if...then:

Code:
if [[ $# -eq 1]]
   then
        if[[ -d $1 ]]
        then
        DIR="$1"
   else
        printf "$ERROR2"
        exit 1
fi

should be:
Code:
$ if [[ $# -eq 1 ]]
then
   if [[ -d $1 ]]
   then
      DIR="$1"
   else
      printf "$ERROR2"
#     exit 1
   fi
fi
[1]+ [[ 0 -eq 1 ]]
$

# 6  
Old 05-16-2010
THANKS!
it seems to be working. still getting this error though

Tail: not found
# 7  
Old 05-16-2010
lower-case T...tail
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell scripting syntax error in if then else

I have one bash shell script to execute table refreshment. At the bottom of script, I have one piece of code to check 'ORA-' error from log file, then send email to DBA or application people. But this piece of code didn't work. I tried different ways and also search online to find where is my... (2 Replies)
Discussion started by: duke0001
2 Replies

2. Shell Programming and Scripting

Error in tsch shell scripting..

Hi Everyone, I am using gdb-7.5 to connect to the target. When I gave the./configure --target=xyz --build=i686-pc-mingw32 --host=i686-pc-mingw32 command then checking build system type... i686-pc-mingw32 checking host system type... i686-pc-mingw32 checking target system type... xyz-mingw32... (3 Replies)
Discussion started by: Heeka
3 Replies

3. Shell Programming and Scripting

Shell Scripting Error - help

I am trying to do an upgrade on a VMWare appliance. I am getting an error, and I dug into the script that is causing the error and will post the statement that is causing the error. Basically, my software seems to want an additional partition before it will do the upgrade. So, I added a new... (1 Reply)
Discussion started by: Phoenix Askevic
1 Replies

4. Shell Programming and Scripting

ERROR in executing mysql querys in shell scripting

Hi All, Please see the below script for mysql 3 commands. Its giving me the right output for all three commands but showing some errors in first two commands , i guess there might be an issue with date. Can anyone help me . #! /bin/bash TABLE_NAME=testingddatabase USER_NAME=root... (3 Replies)
Discussion started by: aish11
3 Replies

5. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

6. Shell Programming and Scripting

Error handling in Unix shell scripting

Hello, I have written a shell script and suppose there is any error in the script. How i can do exception handling in shell script.for example i have below code sqlplus -s <<uid>>/<<pwd>>@<<$ORACLE_SID>> <<EOF > 1_pid1.log set pagesize 0 set feedback off set heading off set linesize 200... (1 Reply)
Discussion started by: rksingh003
1 Replies

7. Shell Programming and Scripting

bash shell scripting error need help urgently

#! /bin/sh abcd = "Hello world" if then echo $abcd fi i got error message that line3 : abcd: command not found line5 : [0: command not found line5 : [1: command not found i have no idea why i got this message. Can some one help me ??? (6 Replies)
Discussion started by: bonosungho
6 Replies

8. Shell Programming and Scripting

shell scripting error

i am trying to work on a simple shell script as #!/bin/bash filename = $2 if ; then echo " Displaying the Content of the file:" filename = $2 cat filename else if ; then echo "Displaying directory listing:" ls -l filename else echo " Commands not correct:" fi done it shows the... (3 Replies)
Discussion started by: phone_book
3 Replies

9. Shell Programming and Scripting

Shell Scripting Error

When i run the script firecall.sh,i am getting a weird error. root: ./var/ADMIN/bin/firecall.sh d12381 ./var/ADMIN/bin/firecall.sh: ?osrc: command not found ./var/ADMIN/bin/firecall.sh: ?osrc: command not found The script is successful,but the error interests me...Any Ideas?? The... (1 Reply)
Discussion started by: Renjesh
1 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question