Imitating DOS functionality: The Call Statment


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Imitating DOS functionality: The Call Statment
# 8  
Old 12-22-2007
in ksh or bash

Code:
if (( 4 + 4 == 8 )) ; then
   test1
else
   test2
fi

or in sh
Code:
#! /usr/bin/sh

if [ `expr 4 + 4` -eq 8 ] ; then
    test1
else
    test2
fi

But I agree with porter, it is better to think in terms of variables.
# 9  
Old 12-22-2007
Ok now I guess its time to get more detailed into what I need.

I have a process that needs to load a tbl. During the process I update an audit table with a start date when i start and an end date when I finish. Because this is a database and because I am loading stage tables I need to make sure that I have the load done before I move on to the next set of data.

The logic in english is as follows:

If the audit table has a start date and a stop date populated then go to the next step.

So in Unix What I want to do is something like
start_date = db2 "select start_date from tbl where audit_job_name = "load" and audit_start_date = "predetermained in the first part of script"
end_date= "similar logic as above"

If start_date is not null and end_date is not null call :Next_Load_Function
else if start_date is null or end_date is null call:Failure_Function
end

I dont know if I am making myself clear. I am a DBA...not a script writer. All I know is the more comlicated the code the harder it is for me to understand Smilie
Let me know if i can clear up the muddy water...
# 10  
Old 12-22-2007
Quote:
Originally Posted by reborg
in ksh or bash

Code:
if (( 4 + 4 == 8 )) ; then
   test1
else
   test2
fi

or in sh
Code:
#! /usr/bin/sh

if [ `expr 4 + 4` -eq 8 ] ; then
    test1
else
    test2
fi

But I agree with porter, it is better to think in terms of variables.
I think this is what I need. Ill play with this for a few days and see what I come up with Thanks for the Help guys!
# 11  
Old 12-24-2007
Here is a question: Can I create a function outside of a script...like create a function .sh file and then call the function from another script?

For example I need to set certain variables in every script, can I write a functoin that does that and then just call the function in every script?

Quote:
Originally Posted by porter
Code:
#!/bin/sh

Test1()
{
    if test "$My_Name" = "$Yourname"
    then
           echo "$My_name" > Name.txt
    fi
}

Test1

Not sure what yours was actually doing.
# 12  
Old 12-24-2007
Quote:
Originally Posted by jadionne
Here is a question: Can I create a function outside of a script...like create a function .sh file and then call the function from another script?

For example I need to set certain variables in every script, can I write a functoin that does that and then just call the function in every script?
You could make use of the source functionality:

Code:
source /some/path/myfunctioncontainer.sh

or

Code:
. /some/path/myfunctioncontainer.sh

depending on what shell you're making use of.
# 13  
Old 12-24-2007
Quote:
Originally Posted by DeepakS
You could make use of the source functionality:

Code:
source /some/path/myfunctioncontainer.sh

or

Code:
. /some/path/myfunctioncontainer.sh

depending on what shell you're making use of.
But I cannot make a .sh file with say 5 functions and then call individual functions at seperate times....
# 14  
Old 12-24-2007
Quote:
Originally Posted by jadionne
But I cannot make a .sh file with say 5 functions and then call individual functions at seperate times....
Why not?

Code:
$ cat myfunc.sh 
#!/bin/sh

f1()
{
        echo Function 1
}

f2()
{
        echo Function 2
}

f3()
{
        echo Function 3
}

f4()
{
        echo Function 4
}

f5()
{
        echo Function 5
}

Code:
$ cat tryem.sh
#!/bin/sh

source /some/path/to/myfunc.sh

f1

touch delfile.trash

f3

foo=$(ls)

f4

f2

echo $foo

f5

rm delfile.junk

Code:
$ ./tryem.sh 
Function 1
Function 3
Function 4
Function 2
delfile.trash myfunc.sh tryem.sh
Function 5
rm: cannot remove `delfile.junk': No such file or directory


Last edited by DeepakS; 12-24-2007 at 10:45 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add new line after 'continue' in if statment

Hello, im creating a csv file for email reporting on issues. my problem is that after 'continue' command in if statment in a loop the new paramter writing into the log doesnt take new line. timeout 4s zabbix_get -I $ZBX -p $PORT -s $IP -k "system.run" if ; then ... (3 Replies)
Discussion started by: batchenr
3 Replies

2. Shell Programming and Scripting

Execute sql statment in korn shell

I am fairly new to writing scripts, and have gotten a lot of help from this site in the past with many of the posts. I have a question/issue with a script I am attempting to write and have a question regarding executing an sql statement inside of a loop (do while). I have in the past written... (1 Reply)
Discussion started by: josbor01
1 Replies

3. Shell Programming and Scripting

Wildcard in a tcsh if statment

Hello everyone I was hoping someone could tell me whether I can use a wildcard inside an tcsh if statement. I am trying to test the argument the user has fed the script and whether it is a .txt file. The Ides behind it is the following if (`echo $1` != *.txt) then echo "wrong... (6 Replies)
Discussion started by: smarones
6 Replies

4. Shell Programming and Scripting

syntax error for if statment test expression

Hi what's the correct way of writing if 1)if "$time_diff" -gt 5 then echo "killing hung process \n" fi 2)if test $time_diff -gt 5 then echo "killing hung process \n" fi where -time_diff=$(($Sam - $current_min)) and current_min=`date +%M` infact both are giving Syntax... (1 Reply)
Discussion started by: Anteus
1 Replies

5. Shell Programming and Scripting

-F option and - V in a single awk statment

Please let me know if I can use -F option and - V in a single awk statment. I want to import some comma separated shell variables using -F option and defining some static variables inside awk using -v option. (2 Replies)
Discussion started by: kalee
2 Replies

6. UNIX for Dummies Questions & Answers

Comparing Special characters (i.e. -,\,/) in an if statment

I need to validate the special characters of a date (the characters between the year and month & month and day). The data filed is being populated by users and read into the script vi an argument. I want to ensure that the date is a '-' (dash) and not a '/' or '\' (slash). The every thing I... (3 Replies)
Discussion started by: angelap
3 Replies

7. UNIX for Dummies Questions & Answers

Clarification for egrep statment

Can someone tell me what exactaly the following command is doing - pid_cmd="/usr/ucb/ps -axww | /usr/bin/egrep '${SUNMC2OSS_PATH}/SunMC2OSS\.jar.* sunmc2oss\.SunMC2OSS\$' | /usr/bin/egrep -v egrep | /usr/bin/nawk '{print \$1}'" Is the egrep is to check "sunmc2oss.SunMC2OSS" process inside... (2 Replies)
Discussion started by: puneet1983
2 Replies

8. Shell Programming and Scripting

if statment, based on retune value

hello im working on a project for the iphone to write a termainal based program we have bsd subsystem installed so have access to most unix command i have a executable called coordinates, which get the coordinates of the iphone when this runs it returns to the terminal the text of... (1 Reply)
Discussion started by: toliver182
1 Replies

9. Shell Programming and Scripting

what is wrong with my awk statment?

I am looking to find something in the hour(in field $2) of 03:00:07 and 04:00:07 and 05:00:07 and must contain something in field 4... why doesn't below command work? I try to use grep .. but since I am running this in loop, it's best I use the awk .. can someone please advise.. I am pretty... (1 Reply)
Discussion started by: hankooknara
1 Replies

10. UNIX for Advanced & Expert Users

hwo do I print ' in an awk statment?

hi 2 all, I'm trying 2 print " ' " in an awk statement but the sign deosn't show. The only way I came with is 2 declare the ' as a variable and call that variable. I'm trying 2 do: awk '{printf("insert into ba_memo_01 values ('%s');",$1)}' and get the output: insert into ba_memo_01 values... (7 Replies)
Discussion started by: baraka
7 Replies
Login or Register to Ask a Question