Simple Shell Script using function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple Shell Script using function
# 1  
Old 04-14-2009
Simple Shell Script using function

Hi all,
I am new to shell scripting.I have made a simple shell script which will give me number of records in a database table. The SQL statement is working fine and there are 11 rows in this table. But problem is that it is not printing this value and fucntion does not get called. Please see the debug output at the end. The variable count2 does not get initialzed. Thanks.

Code:
#!/usr/bin/ksh
set -x
UIDPWD=`cat $TABS_HOME/.restrict/$ORACLE_SID`
export UIDPWD

get_number1()
{
   set -x
   sqlplus -s <<!
   $UIDPWD
   set head off
   set feedback off
   select count(*)
   from MSC041501_090318A
   /
   exit
   !
}
count2 = `get_number1`
echo "The total number of records in file is $count2"

Debug Output:
Code:
+ + cat /export/home/tabs/.restrict/TABST1
UIDPWD=its/its123
+ export UIDPWD
+ get_number1
+ sqlplus -s
+ 0<<
its/its123
set head off
set feedback off
select count(*)
from MSC041501_090318A
/
exit
+ count2 = 11
./count.sql[17]: count2:  not found
+ echo The total number of records in file is
The total number of records in file is


Last edited by zaxxon; 04-14-2009 at 09:48 AM.. Reason: CODE tags are wonderful!
# 2  
Old 04-14-2009
I edited your post, use CODE tags in future please, ty.

problem:
Code:
count2 = `get_number1`

solution:
Code:
count2=`get_number1`

No blanks between var name, = and the value when defining variables in the shell.
# 3  
Old 04-14-2009
thanks a lot...it is working now...
# 4  
Old 04-14-2009
The issue is solved but it is giving an extra line in the output even using the below statement:

count2=`get_number1 | awk '{print $1}'`

count2=
11
+ echo The total number of records in file is
11
The total number of records in file is
11


I want the result like this:

The total number of records in file is 11
# 5  
Old 04-14-2009
Try
Code:
count2=`get_number1 | tr -d '\n'`

# 6  
Old 04-14-2009
thanks...its wokring fine now...

The total number of records in file is 11
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Simple shell script function

Hello, Trying to look vgcheck() { lsvg -o| while read vg; do lsvg -p $vg|grep Missing if ;then echo "OK:PASSED" else echo "FAIL" ... (3 Replies)
Discussion started by: kvosu
3 Replies

2. Shell Programming and Scripting

Help on simple shell script

Hello, I need to create one very simple shell script that checks if the first character of the file ./pump.txt is 0 and in that case gives a message. If the first character is instead 1, it does give a different message. I have written: irr= head -c 1 ./pump.txt if ]; then echo... (4 Replies)
Discussion started by: dcaccount
4 Replies

3. Shell Programming and Scripting

Help on simple shell script

Hello, I am running openmediavault on my Raspberry and I would like to use it as a backup FTP server of snapshots taken from my IP cams. So I get the network recorder to upload every 3 seconds a snapshot to the Raspberry. Everything works perfectly. I would need now a simple script that... (5 Replies)
Discussion started by: dcaccount
5 Replies

4. Shell Programming and Scripting

Help with simple Shell Script

Hi , I am in need of simple shell script that has one input file containing some words Input file 1 : ****ALEX***JOHN*******VIRGIL***** CHRITINE*****FAISAL*****DON***** ****ALEX***JOHN*******VIRGIL***** CHRITINE*****FAISAL*****DON***** ****ALEX***JOHN*******VIRGIL*****... (6 Replies)
Discussion started by: kmanjuna
6 Replies

5. Shell Programming and Scripting

Help me with simple shell script.

Hello forum members, I have to redirect a output of command into a text file inside a script file but iam getting an errors.so please see below script and suggest me for corrections. #!/bin/ksh read IP_ADD echo nslookup $IP_ADD 2>&1| tee log1.txt cat /amex/gcst/siva/Testr/log1.txt... (6 Replies)
Discussion started by: rajkumar_g
6 Replies

6. Shell Programming and Scripting

Simple Shell Script

Hello Friends, I am writing a shell script which will grab a file if it exists and copies it to another folder and will append with current date. I have written but gives me error, plz help: -------------------------------------------- #!/usr/bin/sh source=/home/dev4rice/naveen/test1... (4 Replies)
Discussion started by: ganesh123
4 Replies

7. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

8. Shell Programming and Scripting

simple shell - how to get a parameter typed in a shell script

Hi, I am new to unix and using linux 7.2. I would like to create a script that would make it easyer for me to run my java programms. At the moment I have to type java myJavaprogram I am trying to write a script that will allow me to type something like this "myscript myJavaprogram" or maybe... (4 Replies)
Discussion started by: cmitulescu
4 Replies

9. Shell Programming and Scripting

Simple Shell Script Need Help

I M TRYING TO DO SUM THING I M A NEW LEARNER TO SHELL SCRIPT PLZZZ HELP ME FRIENDS I M TRY TO DO SUM THING C IT AND HELP ME First open a .ctl file Copy the file into temp file Add A EXTRA FIELD “ext_date” with keeping value “##**&&” EG- EXT_DATE CONSTANT"******" Each time... (2 Replies)
Discussion started by: kulbir
2 Replies

10. Shell Programming and Scripting

need a simple shell script

Hi, I am new to unix as well as shell programming. Any body can provide me a simple shell script which should copy/transfer/fetch a file(using FTP)from remote server to local system.and it should log the details when it was fetched.If there is any error,the error msg should log in log... (1 Reply)
Discussion started by: Mar1006
1 Replies
Login or Register to Ask a Question