ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Rep:
Blinking output
The following program doesn't work. I just get a blinking window. What is the problem? Your help is appreciated.
----------------------------------------------------------------
#!/bin/bash
x=0
while [ "$x" -lt 10 ] ; # this is loop1
do
y="$x"
while [ "$y" -ge 0 ] ; # this is loop2
do
echo "$y \c"
y=´echo "$y - 1" | bc´
done
echo
x=´echo "$x + 1" | bc´
done
--------------------------------------
The expected output of the above program is as follows:
---------------------------------------------------------------------------
[ I just get a blinking window and I can't copy and past here. Something with the line 15.]
x=0 [ Here we initialize the variable x. So it is initialized to 0.]
Yes, exactly right!
y=$x [ Here we initialíze the the variable y to x. Obviously x too is a variable.]
Yes again
echo -n "$y"
y=`expr $y - 1` [ These two lines creates the vertical line.]
No. I would prefer to say:
a) the first line displays "y" (without writing a newline)
b) the second line decrements "y"
...
Thank you for the kind words, and I hope that helps .. PSM
PS:
You'll note that I *didn't* leave a space between the numbers.
This is easily accomplished. You can either put a space in "echo" (as you did above), or you can use a tool like "awk" (which permits more sophisticated, "printf-sytle" formatting).
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Original Poster
Rep:
Paulsm4
It doesn't work when I altered it. Please read the following:
#!/bin/bash
x=0
while [ $x -lt 10 ]; do
y=$x
while [ $y -ge 0 ]; do
echo n "$y"
y=`expr $y - 1`
done
echo
x=`expr $x + 1`
done
echo "Done
n 0
n 1
n 0
n 2
n 1
n 0
n 3
n 2
n 1
n 0
n 4
n 3
n 2
n 1
n 0
n 5
n 4
n 3
n 2
n 1
n 0
n 6
n 5
n 4
n 3
n 2
n 1
n 0
n 7
n 6
n 5
n 4
n 3
n 2
n 1
n 0
n 8
n 7
n 6
n 5
n 4
n 3
n 2
n 1
n 0
n 9
n 8
n 7
n 6
n 5
n 4
n 3
n 2
n 1
n 0
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
#!/bin/bash
x=0
while [ $x -lt 10 ]; do
y=$x
while [ $y -ge 0 ]; do
echo "$y"
y=`expr $y - 1`
done
echo
x=`expr $x + 1`
done
echo "Done."
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Original Poster
Rep:
Paulsm4
Thanks for taking time to give me a excellent lengthy reply. Now it is too late here. I am a bit tired because I trained today. As a matter of fact I am training 3 times a week at a gym. I must sleep now.
I will attend this tomorrow. So please keep a good watch on this thread.
Are you based in the USA? If you are in the USA, it is not too late for you.
Distribution: open SUSE 11.0, Fedora 7 and Mandriva 2007
Posts: 1,662
Original Poster
Rep:
I thank both paulsm4 and konsolebox for the help. I am very proud of your knowledge of programming.
Our friend konsolebox has done the same programme in two different ways. Oh! What a talent!
The way konsolebox has made programmes reminds me of the codes use in C++ programming. I worked with C++ programming some years ago. One of his programmes has only 4 lines; it works fine.
The following programme from paulsm4 works fine too.
#!/bin/bash
x=0
while [ $x -lt 10 ]; do
y=$x
while [ $y -ge 0 ]; do
echo "$y"
y=`expr $y - 1`
done
echo
x=`expr $x + 1`
done
So if you know all the pros and cons of programming, you could write a same programme in many different ways. I wish I could write programmes like paulsm4 and konsolebox.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.