Results 1 to 6 of 6
Why doesn't my bash script like my if statement?
What I got so far is
echo -n "Enter Filename:"
s=0
read fn
if (find $fn); then
while read k
do
...
- 08-12-2010 #1Just Joined!
- Join Date
- Aug 2010
- Posts
- 6
help with if statement bash
Why doesn't my bash script like my if statement?
What I got so far is
echo -n "Enter Filename:"
s=0
read fn
if (find $fn); then
while read k
do
echo $k
let $n+$k
done <---- might be wrong $fn
echo " "
echo " "
echo "Sum is" $n
echo " "
read -p "Enter to continue"
done
fi
can someone help me out?
- 08-13-2010 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
what are you trying to do?
the sun is new every day (heraclitus)
- 08-13-2010 #3Linux Enthusiast
- Join Date
- Aug 2006
- Location
- Portsmouth, UK
- Posts
- 539
Bash uses square brackets in if statemetnts []
Take a look at the Bash Introduction to ifRHCE #100-015-395
Please don't PM me with questions as no reply may offend, that's what the forums are for.
- 08-13-2010 #4Just Joined!
- Join Date
- Aug 2010
- Posts
- 6
I'm trying to get numbers from a file and for the script to read the numbers could be any number and any amount of numbers and for the script to add the numbers up in the end
- 08-13-2010 #5Just Joined!
- Join Date
- Aug 2010
- Posts
- 6
[QUOTE=matonb;797751]Bash uses square brackets in if statemetnts []
Maybe that's what's wrong but another person used () and it worked fine for me so I don't know.
- 08-17-2010 #6Just Joined!
- Join Date
- Jul 2006
- Posts
- 6
Try this one:
Code:#!/bin/bash SUM=0 while read -p 'Enter filname: ' FN; do if [[ -f "$FN" ]]; then N=$(<"$FN") (( SUM += N )) echo "Current sum is $SUM." read -p "Press enter key to continue." else echo "Entered file does not exist: $FN." fi done # CTRL-C = abort


Reply With Quote