You are not logged in.
Pages: 1
hey guys, i was hoping for some help. i need to make a script that will constantly add read numbers together until ctrl-d (end of file) is sent. i've got the basic adding part done, but i can't get the until eof part to work, as i have no idea what the eof character is.
here's what i've got:
#!/bin/bash
a=0
until >> eof #this line doesn't work :(
do
read b
a=$(($b+$a))
echo "new number is $a"
done
it's the until >> eof line that i baisically made up because i don't know what it is i need there.
any suggestions?
Offline
Like this?
a=0
while read b; do a=$(($b+$a)); echo $a is new; done
Offline
#!/bin/bash
a=0
while read b #this line doesn't work :(
do
a=$(($b+$a))
echo "new number is $a"
done
you can also replace #!/bin/bash by #!/bin/sh nothing bash specific about that script as it stands
Offline
wow thanks guys, i knew it was an obvious thing that i was missing, thanks for the help.
sidenote; what's the difference between /bin/bash and /bin/sh, is there a disadvantage to putting it over /bin/sh?
Offline
allows it to be run other shells /bin/sh might point to e.g dash or ksh for someone else
Offline
greeat, thanks guys! i appreciate it!
Offline
[stijn@hermes ~]$ ll /bin/sh
lrwxrwxrwx 1 root root 4 jan 28 20:35 /bin/sh -> bash
Sh = symlink to the default shell.
Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy
Offline
Sh = symlink to the default shell.
I hope not. It should only ever link to shells which feature a superset of /bin/sh functionality (ie, not csh and derivatives).
Offline
Interestingly enough, I had to fix some broken shit at work today because of this. Some old scripts were using #!/bin/sh, but using bashisms. The scripts were moved over to a ubuntu server which has /bin/sh -> /bin/dash and hence were no longer working.
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline
Interestingly enough, I had to fix some broken shit at work today because of this. Some old scripts were using #!/bin/sh, but using bashisms. The scripts were moved over to a ubuntu server which has /bin/sh -> /bin/dash and hence were no longer working.
You probably know the quote that it's easier to port a shell than a script, so I'm wandering, how did you fix the situation - installed bash & symlinked?
Offline
Bash was installed, and it wasn't many scripts so I just changed the shebangs.
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline
Pages: 1