Substraction in shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Substraction in shell scripting
# 8  
Old 12-11-2012
Quote:
Originally Posted by Scrutinizer
$(( .. )) is part of the POSIX specification, so in practice it should work with /bin/sh on almost any modern Unix / Linux (On Solaris <=10 use /usr/xpg4/bin/sh)
Yes and no. The POSIX Standards and the Single UNIX Specifications require that the standards-conforming shell be named sh and that it support arithmetic expansions (i.e., $(())), but the standard makes absolutely no requirement that it (or any other standard utility) exist as a file in any particular directory. There is no requirement in the standard that there be a directory named /bin nor that any utility in the standard exist in that directory. The POSIX standards leave a chicken versus egg question about how you find the standard utilities. The documentation for a conforming implementation is required to document how to find conforming utilities on that implementation. Once you know the absolute pathname of the conforming getconf utility, the command:
Code:
getconf PATH

will return a set of directories that can be placed at the front of your setting of $PATH that will find all of the standard utilities. If your implementation concurrently supports more that one standards conforming environment (such as Solaris systems), there will be more than one standards conforming version of getconf (at least one for each environment supporting standards with conflicting requirements). On Solaris systems, /usr/bin/getconf gives you an environment that conforms to System V Interface Definition Issue 3 (SVID3) and X/Open Portability Guide Version 3 (XPG3); /usr/xpg4/bin/getconf gives you an environment that conforms to POSIX.2, POSIX.2a, Single UNIX Specification original version (SUS), SUSv2, and XPG4; and /usr/xpg6/bin/getconf gives you an environment that conforms to POSIX.1-2001 and SUSv3. More details on how Solaris Systems support multiple standards concurrently can be found in the OpenSolaris STANDARDS(5) man page in the man page sets provided on this site.
# 9  
Old 12-11-2012
Hi, yes, but that is why I wrote "in practice". Of all the current Unixen that aspire to be POSIX compliant, Solaris < Version 11 is one of the few (how many others are there?) that does not have a POSIX compliant shell (or a near compliant one) as /bin/sh (even though this is not required or even specified by the standard). So I agree it is best to not rely on this and not specify a shebang and use the proper getconf, but in practice this should work (with the exception mentioned above)..

Last edited by Scrutinizer; 12-11-2012 at 04:25 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Substraction of matching lines from a file.

I have 2 files: file1.txt contains /html/mybook/Charts/143712/reptiles.pdf /html/mybook/Charts/198459/spices.pdf /html/mybook/Charts/198459/fresh_nuts.pdf /html/mybook/Charts/123457/dome_anim.pdf /html/mybook/Charts/123457/vegetables.pdf /html/content/3DInteractive/174091/CSPSGGB.html ... (6 Replies)
Discussion started by: Jojan Paul
6 Replies

2. Shell Programming and Scripting

Problem in algebraic substraction

my code is like this count=`cat /filecount.txt | tail -1 |head -1| awk '{print $1}'` ###file is having value 264 #### echo "actual count = $count" exact_count=`expr $value \* 24` echo "exact_count= $exact_count" diff=`expr "$exact_count" - "$count"` a= exact_count - count ... (8 Replies)
Discussion started by: sagar_1986
8 Replies

3. Shell Programming and Scripting

date substraction

hello i have obtained the current date .. current_date=date "+%m/%d%y" and i have another date ,stored in my log file which i have already retrieved. i want to store the subtraction in a varible called diff. diff=log_date - currentdate ex: log_date=01/28/11 current_date=... (3 Replies)
Discussion started by: urfrnddpk
3 Replies

4. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

5. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

6. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

7. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

8. Solaris

Substraction in bash

Hi all, I have in one script something like this: FIRSTOCC=`grep -n ORA- alert_bill2.log |tail -"$ROWS"|head -1|cut -d: -f1` TOTAL=`more alert*|wc -l` DIFFERENCE=`$TOTAL-$FIRSTOCC` echo Total lines in alert_bill = $TOTAL echo $DIFFERENCE How do I make this substraction work? Thk (2 Replies)
Discussion started by: mclaudiu
2 Replies

9. UNIX for Dummies Questions & Answers

Date Substraction

In Unix script, how to get a "date - 1" ie, yesterday? (4 Replies)
Discussion started by: AC
4 Replies
Login or Register to Ask a Question