if format in functions


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users if format in functions
# 1  
Old 06-23-2009
if format in functions

Hi everyone,
I am receiving this error:
0403-057 Syntax error at line 6 : `}' is not expected.
when I try to enter in my function an if condition of the form:
#! /bin/ksh
do_t(){
var1="testing";recompr=0;
[[ $1 -eq 1 ]] && {printit=0;F_N_s="testing""."xx"."yy;}
}
do_t 1
###########

Am I not doing this right?
if I replace the if with the other format i.e.
if [[ $1 -eq 1 ]];then printit=0;F_N_s="testing""."xx"."yy;fi
it works fine
Please let me know.
Thanks!
# 2  
Old 06-23-2009
Code:
[[ $1 -eq 1 ]] &&  printit=0 && F_N_s="testing""."xx"."yy

Try that.
# 3  
Old 06-23-2009
Hi.
Quote:
{ list;}
list is simply executed. Note that unlike the metacharacters (
and ), { and } are reserved words and must occur at the begin-
ning of a line or after a ; in order to be recognized.

-- excerpt from man ksh
Note the space after the opening curly brace... cheers, drl
# 4  
Old 06-24-2009
Further to previous correspondents.

Quote:
do_t(){
Should be

Quote:
do_t()
{
# 5  
Old 06-25-2009
Hi.

As long as one obeys the syntax rules, many forms are possible:
Code:
#!/usr/bin/env ksh

# @(#) s1	Demonstrate syntax allowed for shell functions, ksh.

echo
export LC_ALL=C
echo "Environment: LC_ALL = $LC_ALL"
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1)
echo

one()
{
  echo " One called." >&2
  return 0
}

two(){
  echo " Two called." >&2
  return 0
}

three(){ echo " Three called." >&2 ; return 0
}

four(){ echo " Four called." >&2 ; return 0 ; }

echo
echo " Results, calling one, two, three, four."
one
two
three
four

exit 0

producing:
Code:
% ./s1

Environment: LC_ALL = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0 
ksh 93s+


 Results, calling one, two, three, four.
 One called.
 Two called.
 Three called.
 Four called.

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need script for transferring bulk files from one format to text format

"Help Me" Need script for transferring bulk files from one format to text format in a unix server. Please suggest (2 Replies)
Discussion started by: Kranthi Kumar
2 Replies

2. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

3. Shell Programming and Scripting

perl module to convert xlsx format to xls format

Hi Folks, I have written a perl script that reads data from excel sheet(.xls) using Spreadsheet::ParseExcel module. But the problem is this module doesn't work for excel sheets with extension .xlsx. I have gone through Spreadsheet::XLSX module with which we can read from .xlsx file directly.... (1 Reply)
Discussion started by: giridhar276
1 Replies

4. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

5. Shell Programming and Scripting

Retaining the Unix CSV format in Excel format while exporting

Hi All, I have created a Unix Shell script whch creates a *.csv file and export it to Excel. The problem i am facing is that Users wants one of the AMOUNT field in comma separted values. Example : if the Amount has the value as 3000000 User wants to be in 3,000,000 format. This Amount format... (2 Replies)
Discussion started by: rawat_me01
2 Replies

6. Shell Programming and Scripting

changing month in Mmm format to mm FORMAT

i have an variable mydate=2008Nov07 i want o/p as in variable mymonth=11 (i.e nov comes on 11 number month) i want some command to do this for any month without using any loop. plz help me (1 Reply)
Discussion started by: RahulJoshi
1 Replies

7. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies

8. UNIX for Dummies Questions & Answers

Convert UTF8 Format file to ANSI format

:confused: Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on... (9 Replies)
Discussion started by: rajreddy
9 Replies

9. UNIX for Advanced & Expert Users

Convert UTF8 Format file to ANSI format

:) Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on this.........Let me... (1 Reply)
Discussion started by: rajreddy
1 Replies

10. Shell Programming and Scripting

convert mmddyy date format to ccyyddd format??

hi, for reading a cobol indexed file i need to convert "mmddyy" date format to "ccyyddd" format. i checked the datecalc and other scripts but couldnt modify them to cater to my need:(... The datecalc gives an output which i believe is the total days till that date, but i want to convert it... (2 Replies)
Discussion started by: Bhups
2 Replies
Login or Register to Ask a Question