Confusion about FOR LOOP syntax between Bourne and BASH shell. Please see.
Will the above code work on a BOURNE shell?
As far as my understanding is, if I am writing the above code in a file..say lol.sh and then running it through the terminal using the command
sh lol.sh
then I am using the Bourne Shell. Am I right with this concept?
If yes, then the above code won't run (as I tried to run it) BUT it runs when i run it as...
bash lol.sh
So my question is that :
1. Am I correct that sh lol.sh will run it using bourne shell ?
2. And can for loop be written in the way it's written in the code above in the bourne shell or
is the only possible syntax of for loop in the bourne shell?
If bourne shells doesn't have math then how am I able to execute statements like
And is it possible to find x to the power of y using expr function (or in any possible way in bourne shell except "for" loop) where x and y are two numbers read from the terminal?
If bourne shells doesn't have math then how am I able to execute statements like
By using the expr external, like I said.
Quote:
And is it possible to find x to the power of y using expr function (or in any possible way in bourne shell except "for" loop) where x and y are two numbers read from the terminal?
Certainly, by running a loop which multiplies x against itself y times.
Thank you for your time but if you would read my last post carefully and not skim over it... you'd see that I said "except for loop" which implies that I already know how to do it with a for loop but I was asking you for some other method "if it exits".
Second thing, I KNOW that it can be done by the expr command but I asked you that WHY I am getting away with using a command like $((...mathematical expression...)) if I am working in the bourne shell WHICH implies that I ALREADY understood that expr can be used.
I do understand if "...am i able to..." couldn't really pass my message along clearly but I think "....except for loop...." was mentioned pretty neatly.
Again, thank you for your time and effort but kindly re read the post before tagging my genuine problem as "homework".
Last edited by navienavnav; 11-10-2011 at 11:59 AM..
A simple "no" would have sufficed. I didn't "tag" your post as homework, I asked.
Most of the time I ask, the answer is "yes". Your question looked contrived, as homework frequently is, because calculating X^Y isn't something that makes much sense to do in a shell. If it was homework, I'd have been breaking the rules by giving you an answer. I've been burned several times by blatant cheaters, too.
If I ask someone what their shell is, and they tell me "Bourne", I ask "which Bourne" because "bourne" means it supports at least the Bourne shell features, not that it's the One and Only True Original Bourne Shell. Some systems -- particularly Linux ones -- use Bash as their Bourne shell, many others use KSH, and a few poor Solaris folks are stuck using an actual ancient pre-POSIX Bourne shell which hasn't been improved since the dawn of UNIX.
If $(( )) works, you're either in bash or ksh.
I don't know a simple syntax for taking a number to a power in either. If I had to do so in basic Bourne, I'd probably pipe "$x^$y" into bc. If you try and do that in $(( )), it's a bitwise exclusive-or, not x to a power, since $(( )) mostly emulates the C expression syntax, and C has no operator for power.
Last edited by Corona688; 11-10-2011 at 12:36 PM..
I have a loop with cases
I am working on Bourne shell
for file in *.${Today}*.csv *.${Today}*.txt\
do
case ${file} in
sun_detail)
do something
;;
sum)
do something
;;
mod)
do something
;;
*)
do something
;; (5 Replies)
Dear all Linux lover,
I am a new learner to Bash Shell script and I would like to writing a script to to repeat my script.
This mean I would like to have multiple same of result after running the .sh.
#######
TIMES_NO=0
echo -n "Please enter the number for times to repeat ?"
read... (10 Replies)
Hi,
I am using a for loop to manipulate files data_1.txt through data_100.txt. The for-loop is set up like this:
for i in {1..100}; do cut -f1 data_$i.txt > output$i.txt
I get the following error message when I run the code:
cannot open `data.txt' for reading: No such file or directory... (4 Replies)
Hello forum,
I hope my problem is easy to solve for someone in here!
My main task is to copy a large amount of imap-accounts from one server to another. There is a tool (Perl) called imapsync which does the job exellent. Unfortunately I'm only able to run it on one account at a time.
After... (3 Replies)
Hello,
I am relatively new to UNIX scripting and am learning a lot. I have already tried several searches on this website and have tried various syntax options suggested to no avail. I am obviously not writing the script correctly. I really do appreciate any and all the help.
Below is an... (8 Replies)
Hello
I am having issues with a script I'm working on developing on a Solaris machine.
The script is intended to find out how many times a particular user (by given userid) has logged into the local system for more than one hour today.
Here is my while loop:
last $user | grep -v 'sshd'... (7 Replies)
Hello Everyone....
I am trying to print a number sequence in following format using for loop.
I am using a bourne shell. I tried following for loop condition but it is bash syntax.
for (( i=0; i<=5; i++ ))
It is giving syntax error.
Kindly help with the syntax of "for"... (7 Replies)
I do not claim to be an expert, but I have done things with scripts that whole teams of folks have said can not be done. Of course they should have said we do not have the intestinal fortitude to git-r-done.
I have been using UNIX actually HPUX since 1992. Unfortunately my old computer died and... (7 Replies)
I have file named script1 as follows:
#!/bin/bash
count="0"
echo "hello"
echo "$count"
while
do
echo "$count"
count=`expr $count + 1`
done
-----------
when I run it, I get
./script1: line 9: syntax error near unexpected token `done'
./script1: line 9: `done'
I... (6 Replies)
how to use if-loop in bourne shell with multiple conditions like follows
if
then
commands
fi
it gives me an error
test: ] missing
then i put
if ]
it gives me an error
[[ not found
kindly i need the syntex for the bourne shell (5 Replies)