Execution issue with shell script - works in a different environment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution issue with shell script - works in a different environment
# 1  
Old 03-25-2009
Execution issue with shell script - works in a different environment

Hi
I get the following error while executing the shell script. I did not get an error when I ran the script in a different environment (unix server).
str-token.ksh[15]: 0403-057 Syntax error at line 20 : `(' is not expected.
This is the line which gives error
string=(${pos_array[i]})

Please find the code below.
Code:
# $1 is pos file and $2 is input file

# column positions are read into pos_array
index=0
newfile="outfile"
> $newfile
while read line;
do
pos_array[$index]="$line"
index=$(($index+1))
done < $1

# read each line, find substring
while read line1;
do
i=0
while [ $i -lt $index ]
do
string=(${pos_array[i]})
pos1=${string[0]}
pos2=${string[1]}
pos1=$(($pos1-1))
pos2=$(($pos2-$pos1)) #no of columns
field=${line1:$pos1:$pos2}
#echo "field is $field"
tmpfield=`echo "$field" | sed -e 's/^\([0-9.]*\)\(-*\)\( *$\)/\2\1\3/;'`
#echo "tmpfield is $tmpfield"


echo -n "$tmpfield" >> $newfile
i=$(($i+1))
done
echo >> $newfile
done < $2

Please advise.
# 2  
Old 03-25-2009
Remove the parentheses from that line.

Regards
# 3  
Old 03-25-2009
Thanks for your suggestion. But if I remove the paranthesis, I get an error like this

-----
$pos1: 1
$pos2: 10
str-token.ksh[33]: field=${line1:$pos1:$pos2}: 0403-011 The specified substitution is not valid for this command.
------

Please let me know if this "field=${line1:$pos1:$pos2}" is not allowed in Unix
# 4  
Old 03-25-2009
Quote:
Originally Posted by hidnana
[...]
str-token.ksh[33]: field=${line1:$pos1:$pos2}: 0403-011 The specified substitution is not valid for this command.
------

Please let me know if this "field=${line1:$pos1:$pos2}" is not allowed in Unix
The syntax above is supported by ksh93 and bash. It seems you're trying to execute the script with a different shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Expect scripting issue, works interactively when doing commands in cli, does not work in script

Hi; problem may be obvious, simple but I have to say it is somehow not easy to locate the issue. I am doing some word extracting from multiline text. Interacting in CLI seems to work without issues. First step is to add multiline text to a variable. expect1.1> expect1.1> set... (2 Replies)
Discussion started by: aldowski
2 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

4. Shell Programming and Scripting

perl: Command works in terminal, but not in shell script

Hi, the following command works in the terminal no problem. samtools view -h rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar... (8 Replies)
Discussion started by: jdilts
8 Replies

5. Shell Programming and Scripting

variable assigment not works in shell script

Hi, The following assigment is not working within shell script but is working from command line. Could anybody advise why? OS - solaris 8 APPL=`grep "$Application" ldapapps |awk '{print $1}'` echo $APPL (5 Replies)
Discussion started by: urello
5 Replies

6. UNIX for Dummies Questions & Answers

I've no idea how this command works and I've no test environment to see it's output

`echo $variable | cut -c$((${#variable}))-` I know the working of echo,pipe and cut to some extent. Thanks in advance . Video tutorial on how to use code tags in The UNIX and Linux Forums. (2 Replies)
Discussion started by: Ion_Shell
2 Replies

7. Shell Programming and Scripting

how the typeset command works in shell script

typeset -l section section=${2:-.} what does these 2 lines meaning? (1 Reply)
Discussion started by: venkatababu
1 Replies

8. Shell Programming and Scripting

Works in shell but not script UNIX

ok i have a very simple UNIX script #!/bin/bash TERM=ansi;export TERM PFCMARK=25;export PFCMARK umask 0000 PFUMASK=000;export PFUMASK #run for filepro menus and exectuables echo "###########File Modification Log.############\r" > "/public/appl-fp$(date +%m-%d-%Y).txt" find /appl/fp/... (10 Replies)
Discussion started by: dunpealslyr
10 Replies

9. Shell Programming and Scripting

Issue with script in linux but in unix works

I have this simple script: #! /usr/bin/sh #***************************************************************************** # *** get_input (question variable) *** #***************************************************************************** get_input () { echo "${BOLD}${1} : " read... (14 Replies)
Discussion started by: C|KiLLeR|S
14 Replies

10. Shell Programming and Scripting

Expect Issue Serial Forground Execution vs Concurrent Background Execution

I have an expect script that interrogates several hundred unix servers for both access and directories therein using "ssh user@host ls -l /path". The combination of host/path are unique but the host may be interrogated multiple times if there are multiple paths to test. The expect script is run... (2 Replies)
Discussion started by: twk
2 Replies
Login or Register to Ask a Question