I need to have two variables and want to perform an addition with these variables in shell script. I am using the below script for this, but i have got expr: non-numeric argument error while running the same.
Code:
#!/bin/sh
val1=10
val2=20
while [val1 -gt 5]
do
echo $val1
val1=$(expr $VAL + $BAL)
done
Please help me here.
Hello,
Im trying to work on a small script for a formula converting temperatures, Celsius to fahrenheit.
I have a formula, and it works.... it works every way I try it. But it keeps giving me the wrong results every time with expr.
The formula for C to F would be:
divide by 5, multiply by 9, add 32.
So.....
hii please help me this is the script
Code:
num=$1
sum=0
while [$num -ne 0]
do
x=`expr $num % 10`
sum=`expr $sum + $x`
num=`expr $num / 10`
done
echo "Summation is $sum"
it is giving error
pratyush@ubuntu:~$ sh shell.sh 123
shell.sh: 11: 123: not found
Summation is 0
please help!!!
I wrote the following script:
#!/bin/bash
SAVEIFS=$IFS
alias export='export'
IFS=$(echo -en "\n\b")
find $1 -name "*" -a -type f -exec sh -c let len=`expr length {}` \; -exec sh -c let str=`expr substr {} 1 len-3` \; -exec ffmpeg -y -i {} $str.mp3 \;
# restore $IFS
unalias export
IFS=$SAVEIFS
Problem:
You know when more one shell you can't export your variable in other shell,
I'm learning Shell scripting for a diploma in IT I'm currently doing. I'm trying to write a small script that adds two numbers as shown as in one of the tutorials we were given.
echo "Enter two numbers"
read num1 num2
sum = 'expr $num1 + $num2'
echo "The sum is = $sum"
However when I give it the execution permission and run the script, it gives me this error.
sum: =.
Hi,
I have used expr command to increment the date.
for e.g.,
case 1 :
Code:
echo $(date -d $(echo `expr 20010101 + 1`))
it returns
Code:
Tue Jan 2 00:00:00 IST 2001
case 2:
Code:
echo $(date -d $(echo `expr 20010101 - 1`))
it returns
Code:
date: invalid date `20010100'
please suggest me, how to solve the problem.
Thanks and Regards
Nanthagopal A
Hi guys i just started Shell scripting today and doing a very basic Shell script but i am not getting the correct output i don't now why please help me.
I am using Ubuntu 12.10
The code i written is:
#!/bin/bash
echo Enter Sides
read l
read b
area='expr $l \* $b'
echo The area of rectangle with sides $l and $b is $area
echo Enter radius
read r
area='expr $r \* $r \22'
area='expr $area / 7'
echo
Hi Guys! I need to solve this.
I want an array to be created by a certain calculation for which I created a function. Now this array is not getting created. See script below I want array b to be the factorial value of array element a. Help is needed. Thanks!
Code:
#!/bin/bash
.
Hello Guys,For my homework I must write a shell script to do this serie,
I know that I must use the "bc" for that, but for the script's itself i have no idea,(beginner)
Can you plz just help me for have some idea?
Thanks
I wrote a program baut it does not work,
#!/bin/sh
echo "Input number"
read n
counter=0
ans=1
while [ $counter -ne $n ]
do
ans=`expr 4*(-1/(2*$count