Sponsored Content
Top Forums Shell Programming and Scripting Getting error -: more tokens expected in shell script Post 302844261 by Don Cragun on Sunday 18th of August 2013 02:31:12 AM
Old 08-18-2013
Quote:
Originally Posted by bakunin
Don got it right, already, but i want to know what the "&&" is supposed to do? If you want to do what i think this is supposed to do (combine two conditions with a logical AND) you might consider:

Code:
if [[ $k -le $kkm -a ${k:-0} -ne 0 ]]; then

I hope this helps.

bakunin
Yes, && between two commands evaluates to true if both commands evaluate to true.

But, the command:
Code:
if [[ $k -le $kkm ]] && [[ ${k:-0} -ne 0 ]]; then

is not equivalent to:
Code:
if [[ $k -le $kkm -a ${k:-0} -ne 0 ]]; then

There are a few problems with the above that include, but might not be limited to:
  1. -a is required to be accepted by POSIX conforming implementations of the utilities test and [ only if the implementation supports the X/Open System Interfaces option and even then is marked obsolescent. The standards don't currently define the [[ conditional expression syntax, but shells that do support -a as an operator in expression in commands of the form [[ expression ]] (including both bash and ksh) treat -a in [[ expression ]] as an obsolescent synonym for the unary -e filename operator rather than the binary logical and operator that is supported by some versions of test and[.
  2. It is still using unquoted (possibly unset or set to empty string) variables k and kkm.
  3. And, there is still no verification that k and kkm are numeric strings.
One way to reliably perform this test using any POSIX conforming shell is:
Code:
if [ "${k:=0}" != "${k#*[!0-9]}" ]
then    printf "k (%s) is not a numeric string\n" "$k" >&2
        exit 1
else    printf "k is a numeric string (%s)\n" "$k"
fi
if [ "${kkm:=0}" != "${kkm#*[!0-9]}" ]
then    printf "kkm (%s) is not a numeric string\n" "$kkm" >&2
        exit 2
else    printf "kkm is a numeric string (%s)\n" "$kkm"
fi
if [ $k -le $kkm ] && [ $k -ne 0 ]
then    printf "%s <= %s and %s != 0\n" $k $kkm $k
else    printf "%s > %s or %s == 0\n" $k $kkm $k
fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

: + : more tokens expected

Hello- Trying to add two numbers in a ksh shell scripts and i get this error every time I execute stat1_ex.ksh: + : more tokens expected stat1=`cat .stat1a.tmp | cut -f2 -d" "` stat2=`cat .stat2a.tmp | cut -f2 -d" "` j=$(($stat1 + $stat2)) # < Here a the like the errors out echo $j... (3 Replies)
Discussion started by: Nomaad
3 Replies

2. Shell Programming and Scripting

Shell script to parse/split input string and display the tokens

Hi, How do I parse/split lines (strings) read from a file and display the individual tokens in a shell script? Given that the length of individual lines is not constant and number of tokens in each line is also not constant. The input file could be as below: ... (3 Replies)
Discussion started by: yajaykumar
3 Replies

3. Shell Programming and Scripting

Shell Script to replace tokens in multiple files

I have multiple script files that I have created, that allow me to simply replace a few tokens at the top of the file, and then not have to go through the actual script and change anything. I have about 10 of them, but I was hoping to find a way to write a small script that would allow me to input... (20 Replies)
Discussion started by: cbo0485
20 Replies

4. Shell Programming and Scripting

Script - Expression not complete more tokens expected

I have the following script to output a report of response times - but it is throwing the error: ./jobname: -: 0403-053 Expression is not complete; more tokens expected. Here is the code, any ideas what the problem is? (line 46 is simply, LC=0) FILE2=/templogs/access_log... (9 Replies)
Discussion started by: daveaasmith
9 Replies

5. Shell Programming and Scripting

+: more tokens expected

Hey everyone, i needed some help with this one. We move into a new file system (which should be the same as the previous one, other than the name directory has changed) and the script worked fine in the old file system and not the new. I'm trying to add the results from one with another but i'm... (4 Replies)
Discussion started by: senormarquez
4 Replies

6. Shell Programming and Scripting

Need tokens in shell script

Hi All, Im writing a shell script in which I want to get the folder names in one folder to be used in for loop. I have used: packsName=$(cd ~/packs/Acquisitions; ls -l| awk '{print $9}') echo $packsName o/p: opt temp user1 user2 ie. Im getting the output as a string. But I want... (3 Replies)
Discussion started by: AB10
3 Replies

7. UNIX for Dummies Questions & Answers

Test: argument expected error in shell script

Hi, I am trying to write a small script that validates if there exist files that start with a pattern in a given directory. Below is the piece of my script: #!/usr/bin/ksh BTFDIR=/opt/ships/temp if then echo 'found' else echo 'not found' fi When I run this... (2 Replies)
Discussion started by: snvniranjanrao
2 Replies

8. Shell Programming and Scripting

Binary Operator expected while executing the below shell script.

Hi Experts, Iam bit poor in shell scripting, Here my requirement is for generating an alert where the oracle database db_recovery_file_dest_size usage. If it reaches beyond 80% should recieve an alert through an email. Want to schedule this alert in cron. #!/bin/bash .... (9 Replies)
Discussion started by: Jagadish m
9 Replies

9. Shell Programming and Scripting

AIX 6.1 Error: 0403-053 Expression is not complete; more tokens expected.

Hi I have been trying every possible solution available for this error on this Forum but could not resolve it. When i am running the below script i get this error.:mad: sh diskMonitor.sh diskMonitor.sh: -: 0403-053 Expression is not complete; more tokens expected. diskMonitor.sh: -:... (5 Replies)
Discussion started by: nitinkatipn
5 Replies

10. UNIX for Beginners Questions & Answers

Passing Arguments to shell script from file is not working as expected.

Hi All, I have below simple shell script in cloudera quick start vm cenos 6 which copy file from source to destination. # file_copy.sh source_dir = ${source_dir} target = ${target_dir} cp source_dir target and my parameter file is like below #parameter_file.txt source_dir =... (4 Replies)
Discussion started by: Narasimhasss
4 Replies
All times are GMT -4. The time now is 10:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy