function in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting function in UNIX
# 1  
Old 02-26-2009
function in UNIX

Hi,

I have an array of data as below:
df[1] = trx
df[2] = xml

I would like to create a function which contains array inside it and the value is determined when the function is called as below:


function pass_or_fail
{
if [ -s fail/${df[$i]} ]
then
echo " ${df[$i]} FAILED. Please check logs"

elif [ -s pass/${df[$i]} ]
then
echo " ${df[$i]} PASSED."
fi
}

echo "\n Data Loading Summary"
echo " --------------------"
echo "\n trx data loading :"
pass_or_fail 1 ## function calling for $i value = 1
echo "\n xml data loading :"
pass_or_fail 2 ## function calling for $i value = 2


Can anybody check what I am missing here because this looks not working for me Smilie

Thanks!
# 2  
Old 02-26-2009
df[$1] instead of df[$i]?
# 3  
Old 02-26-2009
Try:
function pass_or_fail
{
eval local=\${${df}[\$i]}
if [ -s fail/${local} ]
then
echo " ${local} FAILED. Please check logs"

elif [ -s pass/${local} ]
then
echo " ${local} PASSED."
fi
}
# 4  
Old 02-26-2009
Hi Perderabo,

Thanks for your input, I used that in my script but I got this error message after that

Data Loading Summary
--------------------

trx data loading :
./load.sh[2]: local=${[$i]}: bad substitution
# 5  
Old 02-26-2009
I misunderstood your requirements. I now agree that you need to use $1 instead of $i or do:
i=$1
# 6  
Old 02-26-2009
Hi Perderabo..

I need to call the function outside it with these code:

pass_or_fail 1 ## function calling for $i value = 1, so i can get df[1]=trx value

pass_or_fail 2 ## function calling for $i value = 2, so i can get df[2]=xml value
# 7  
Old 02-26-2009
Hi Perderabo..

I need to call the function outside it with these code:

pass_or_fail 1 ## function calling for $i value = 1, so i can get df[1]=trx value

pass_or_fail 2 ## function calling for $i value = 2, so i can get df[2]=xml value
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

String Function in UNIX

Hi - Have file1 which has the below date 08/31/2018 And also have file2 which has the below texts ASOF:<CMODate> FUND I need to read the second file if it has colon (:) then move the date from first file to second file like this ASOF:08/31/2018 have used cut -d":" -f1 and moved the... (2 Replies)
Discussion started by: Mohan0509
2 Replies

2. Shell Programming and Scripting

UNIX Date function with -d options

Hi , I couldn't understand how this program works. Can somebody please explain it to me. DT=`date -d "1 day"` # This part I understand echo ${DT/ */} # How this works echo ${DT/* /} (2 Replies)
Discussion started by: LoneRanger
2 Replies

3. Shell Programming and Scripting

Split function in HP UNIX

hi all, i have large file. where i need the split the files into two files. can anyone tell me what is the command for that? Unix OS :HP Unix. Thanks, arun. (2 Replies)
Discussion started by: arun888
2 Replies

4. Shell Programming and Scripting

Sort function UNIX bug ???

Hello there i have a funny behiavor of the sort fonction, i try it out on different Solaris machine and i have the same issue. So i would like to see if there is a rationel explanation here is some data in a file:test.txt ,Test,RSD,RSD_Asset ,Test,RSD,RSD_Credit ,Test,RSD,RSD_Liab... (3 Replies)
Discussion started by: kykyboss
3 Replies

5. Shell Programming and Scripting

UNIX function

I have a code like this v_time=12:12:12 correctTimeFlag=$(echo $v_time|awk '{for(i=1;i<=NF;i++) if( $i ~ /::/){print i}}') if then echo "correct" fi I need a equivalent function to replace the line correctTimeFlag=$(echo $v_time|awk '{for(i=1;i<=NF;i++) if( $i ~... (3 Replies)
Discussion started by: swayam123
3 Replies

6. Solaris

function parameter in unix

Hi, How to use a function with passing value as a parameter in unix ? With Regards (7 Replies)
Discussion started by: milink
7 Replies

7. Shell Programming and Scripting

Recursive function in unix

Can someone tell me, how do i write a recursive code using shell ( eg like 'for' loop in C) which outputs the record to a database table as one row per iteration? (7 Replies)
Discussion started by: goutam_igate
7 Replies

8. UNIX for Dummies Questions & Answers

Trouble with UNIX tr (translate) function

UNIX script - problem. I want the spaces in my Item variable to be replaced with a question mark. Can you tell me what I am doing wrong? This is the whole code line. Item | tr -s " " "?" Why is this not making any changes to the Item value? Thanks for any help you can give! tg (2 Replies)
Discussion started by: by_tg
2 Replies

9. Cybersecurity

Function of Javascript within Unix Network

What attacks can a Unix box get through Javascript? Is the Web Client secure against Javascript attacks if any? Do we have a Trojan horse made in JavaScript? (3 Replies)
Discussion started by: netass
3 Replies

10. Programming

decrypt function in unix?

Hai Friends We have a function called char * crypt(const char *ps, const char* key) to encrypt the password in the unix environment.. Do we have any decrypt function to decrypt it? If not then how can we verify the password through program? Thanks in Advance Collins (1 Reply)
Discussion started by: collins
1 Replies
Login or Register to Ask a Question