The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
scipt dividing strings /reg expr maco_home UNIX for Dummies Questions & Answers 3 08-30-2007 06:39 AM
math.h: float ceilf(float x) jonas.gabriel High Level Programming 1 06-14-2007 12:20 AM
dividing a file into two jazz High Level Programming 2 10-20-2006 04:55 AM
comparing two float values kavitha Shell Programming and Scripting 2 04-02-2004 10:32 PM
dividing the screen >>> ShockTeam UNIX for Dummies Questions & Answers 4 11-06-2001 05:29 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-16-2007
Registered User
 

Join Date: Jan 2007
Posts: 17
Dividing float values

Hi

I know its a dumb question but can any one please explain me the difference of executing a shell script in the following 2 ways.

. script.sh
sh script.sh

I have a problem if I execute the following code as sh script.sh

DB_CNT_ALW=0.20
SCT_VAR=0.05

if [ "$(echo "if (${DB_CNT_ALW} > ${SCT_VAR}) 1" | bc)" -eq 1 ]; then
echo "== Difference is greater"
else
echo "== Difference is not greater"
fi

The above mentioned code was suggested by vgersh99. But the same code works well if I execute the script as . script.sh
I would prefer executing the script as sh script.sh since if I use exit command inside the script it won't come out of unix but instead exit from the script.

Thanks
Shash
Reply With Quote
Forum Sponsor
  #2  
Old 01-16-2007
Glenn Arndt's Avatar
Anomalous Lurker
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
". script.sh" will execute the script in the current environment, as if you had typed all the commands in script.sh at the command prompt. Therefore, an "exit" in the script will exit your session. Why not just chmod +x the script and run it by doing:
Code:
./script.sh
?
Reply With Quote
  #3  
Old 01-16-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
You can't run that script as:
sh script.sh
because sh is an ancient shell that cannot run that code. You need to use
ksh script.sh
bash script.sh
or some other reasonably modern shell.
Reply With Quote
  #4  
Old 01-17-2007
Registered User
 

Join Date: Jan 2007
Posts: 17
Thanks Glenn Arndt & Perderabo!!

Both the solutions are working.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0