Bash Calculator issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Calculator issue
# 1  
Old 07-21-2009
Bash Calculator issue

Hello, I'm relatively new to using bc so I could use some help. In this script im working on I want to have the bc function to calculate float numbers for imagemagicks convert charcoal. Below is what I'm talking about. There are no syntax errors but when it outputs the users frames for example 0-10 the filter remains at an integer value. I want the filter to integrate with bc. I appreciate all help I can get. Thank you.

Code:
    count=$START
    SETSTEPS=$ (echo "scale=1; 1/25" | bc)

    SETTING=$SETSTEPS
    echo $SETSTEPS

        while [ $count -le $END ]; 
        do
        #echo $count

    #set for padding of 4 from 0-999.

        if [ $count -lt 10 ]; then 
        convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.000$count.jpg
        fi

        if [ $count -ge 10 ] && [ $count -le 99 ]; then
        convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.00$count.jpg
        fi
        
        if [ $count -ge 100 ] ; then
        convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.0$count.jpg
        fi


        SETTING=$(echo "scale=4; $SETTING+$SETSTEPS" | bc)
        echo "processing frame: $count"

        let count=count+1

        # to view in maya's fcheck plugin
        #fcheck -n $START $END 1 ${OUTDIR}${OUT}.@@.jpg
        done

# 2  
Old 07-21-2009
Looks like you need to specify 2 decimal places:
Code:
$ echo "scale=1;1/25" | bc
0
$ echo "scale=2;1/25" | bc
.04
$

# 3  
Old 07-21-2009
Still not integrated

Hey I changed a few things around and the setting for which the values to change are working as they should now. I still don't understand where I'm going wrong to make the filter integrate with those values. Without the bc the filter on the image sequence is the same as it is with the bc command.

Code:
count=$START
    SETSTEPS=$(echo "scale=2; 1/2" | bc)
    SETTING=$SETSTEPS
        while [ $count -le $END ]; 
        do
        echo $count

        #set for padding of 4 from 0-999.

        if [ $count -lt 10 ]; then 
        convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.000$count.jpg
        fi


        if [ $count -ge 10 ] && [ $count -le 99 ]; then
        convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.00$count.jpg
        fi

        if [ $count -ge 100 ] ; then
        convert ${IMGDIR}${IMG} -charcoal $count ${OUTDIR}${OUT}.0$count.jpg
        fi

        SETTING=$(echo "scale=2; $SETTING+$SETSTEPS" | bc)
        echo "processing frame: "$count " setting is: " $SETTING "setsteps is " $SETSTEPS""

        let count=count+1

This is from the terminal. I want this math to integrate with the filter output of the image. Basically the image goes lighter to darker over time, I want it to get darker at a slower rate. I know 1/2 wont do that but this is just an example.


Code:
processing frame: 0  setting is:  1.00 setsteps is  .50
1
processing frame: 1  setting is:  1.50 setsteps is  .50
2
processing frame: 2  setting is:  2.00 setsteps is  .50
3
processing frame: 3  setting is:  2.50 setsteps is  .50
4
processing frame: 4  setting is:  3.00 setsteps is  .50
5
processing frame: 5  setting is:  3.50 setsteps is  .50
6
processing frame: 6  setting is:  4.00 setsteps is  .50
7
processing frame: 7  setting is:  4.50 setsteps is  .50
8
processing frame: 8  setting is:  5.00 setsteps is  .50
9
processing frame: 9  setting is:  5.50 setsteps is  .50
10
processing frame: 10  setting is:  6.00 setsteps is  .50


Last edited by jsells20; 07-21-2009 at 07:18 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare bash arrays issue

Hello everyone, I need help comparing 2 arrays. the first array is static; the second array is not .. array1=( "macOS Mojave" "iTunes" ) cd /Volumes array2=( * ) # output of array2 macOS Mojave iTunes Mac me The problem occurs when I compare the arrays with the following code - ... (6 Replies)
Discussion started by: trexthurman
6 Replies

2. Shell Programming and Scripting

Bash arithmetic issue

I found the following issue by simply increasing a variable. The ((A++)) expression returns an error, the other expressions both return 0. Does anyone know why? script.sh: #! /bin/bash A=0 B=0 C=0 ((A++)) ; echo "${?}" ((B=B+1)) ; echo "${?}" ((C+=1))... (8 Replies)
Discussion started by: elbrand
8 Replies

3. Shell Programming and Scripting

Array Issue In Bash

Hi, I have the following code which is giving error mentioned below. Please can you support on this. Also suggest how can we access all the items against single vasservicename in circlename array,i.e, vasservicename say MTSTV will be available to all circles which are mentioned in the array... (2 Replies)
Discussion started by: siramitsharma
2 Replies

4. Shell Programming and Scripting

Bash script and remote server issue

Hello, I'm attempting to run a script on a remote server via SSH but am having issues getting the script to run using proprietary binaries located on the remote server as it keeps complaining that commands are invalid on the local machine. If I run the script locally on the remote server, it... (2 Replies)
Discussion started by: shadyuk
2 Replies

5. Shell Programming and Scripting

bash ls command file issue

ls -l /md01/EL/MarketData/inbound/ststr/INVENTORY* |tail -5 |awk '{ print $5,$6,$7,$8,$9 }'If I run the above from the command line the output to md_email is formatted correctly as 78213497 May 1 12:50 /md01/EL/MarketData/inbound/ststr/INVENTORY.20120430.PINESTREET.CSV.done 77904740 May 2... (3 Replies)
Discussion started by: smenago
3 Replies

6. Shell Programming and Scripting

syntax issue mysql in bash script

I'm running mysql in a bash script mysql <<EOF query EOF one query is like this: UPDATE $dbname.$prefix"config" SET value = $var WHERE "$prefix"config.name = 'table colname'; with variable but it's giving an error i'm not sure what to put for "$prefix"config.name the table... (3 Replies)
Discussion started by: vanessafan99
3 Replies

7. Shell Programming and Scripting

variable issue in a bash in a shell script

Hi, I am trying to write a PBS shell script that launches a bash process. The issue is that the bash process needs a variable in it and the shell script is interpreting the variable. How do I pass this as a literal string? Here is my code snippit: TMP=".fasta" FILEOUT=$FILE$TMP cd... (2 Replies)
Discussion started by: bioBob
2 Replies

8. Shell Programming and Scripting

bash in perl issue

I use the following shell script in bash and it works fine. It returns 1 # cat /etc/httpd/conf/res.txt maldet(24444): {scan} scan completed on eicar_com.zip: files 1, malware hits 1, cleaned hits 0 # if ]; then echo 0 > /etc/httpd/conf/malflag; else echo 1 > /etc/httpd/conf/malflag;... (2 Replies)
Discussion started by: anilcliff
2 Replies

9. Shell Programming and Scripting

bash integer & string issue

Hi guys, I need for the bash code below a little bit help: cat script.sh #!/bin/bash 5_MYVALUE="test" echo "$5_MYVALUE" If I try to run the script, got follow failure: ./script.sh ./script.sh: line 4: 5_MYVALUE=test: command not found _MYVALUE My questions are how... (4 Replies)
Discussion started by: research3
4 Replies

10. Shell Programming and Scripting

bash version or string issue

Hi all, I'm not sure but I guess, that is a bash version issue. The script working fine on "GNU bash, version 3.2.25(1)-release Ubuntu". #!/bin/bash while IFS=">" read a id val do if ] then VAL=${id%<*}; ID=${id#*</} echo $VAL echo $ID sed... (5 Replies)
Discussion started by: research3
5 Replies
Login or Register to Ask a Question