Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
The program can be started with numbers parameter between 1 and 9. If it is not given parameter, the program will ask user about a number between 1 and 9. Then the program should print "pyramid" using "double loop" - loop inside loop :
1
22
333
4444
etc. to spoken numbers. If you manage to get this variation is even better:
1
22
333
4 4 4 4
etc. To spoken numbers.
Can somebody help? We are a group of 4 totally new to the linux commander.
So completely new to a class teaching you how to do scripting (amongst other things). So what have you done so far? Do you know how to ask the user for information? Do you know how to store that information? Do you know how to check that information is in the range 1 to 9 or that it is even a number??
I imagine the teacher did not set this on the first day without teaching you anything, so help us to understand where you are up to?
So completely new to a class teaching you how to do scripting (amongst other things). So what have you done so far? Do you know how to ask the user for information? Do you know how to store that information? Do you know how to check that information is in the range 1 to 9 or that it is even a number??
I imagine the teacher did not set this on the first day without teaching you anything, so help us to understand where you are up to?
I know some few things, as making easy scripts. He went through alot in a very short time, so it wasn't easy at all.
We don't know how to ask the user for information or how to store it.
"help us to understand where you are up to?" We are making a program with shellscripting?
We have done this so far:
Quote:
#!/bin/bash
for i in {1..5}; do
for j in $(eval echo {1..$i}); do
echo -n $i
done
echo
done
I just asked for help, not for people to do the task for us. If that wasn't clear enough, i'm pointing that out here.
#!/bin/bash
for i in {1..5}; do
for j in $(eval echo {1..$i}); do
echo -n $i
done
echo
done
I just asked for help, not for people to do the task for us. If that wasn't clear enough, i'm pointing that out here.
That's more than half the job done, very good.
Now you have to check whether the first argument "$1" is between 1 and 9. If yes, assign it to x and use it as upper boundary for the first loop. Else "read x" from standard input. I assume that you already you had "if ... then ... else ... fi" in your lesson. That should bring you a bit further.
7. As an alternative to your eval and a sequence, try looking up a for loop control, using the form :- counter; counter expression number;counter[inc/dec]
Hope some of that helps too. Below is a site you may wish to work through:
You may also want to try writing test scripts for each of the things mentioned by grail, before building the whole script in one.
This way you understand how each concept works.
FYI add this at the top of your scripts to see what is going on
Code:
#!/bin/bash
set -xv # this line shows the parser in action
If it is not given parameter, the program will ask user about a number between 1 and 9
In other words, what you need to do FIRST is to check if an argument was passed or not. If an argument was NOT passed, then you should ask for user input.
I will give you a hint with regards to the first problem (checking for an argument):
Code:
$#
Quote:
Originally Posted by Kjakan
Dette blir sett paa som juks.
Hilsen Tor L
^If you are the instructor, then you ought to know that using forums to ask for help has been done in the GNU/Linux community since day one. This is not cheating, this is asking for help. Furthermore, much respect to the OP for clearly stating in the first post that this is a school project.
In other words, what you need to do FIRST is to check if an argument was passed or not. If an argument was NOT passed, then you should ask for user input.
I will give you a hint with regards to the first problem (checking for an argument):
Code:
$#
^If you are the instructor, then you ought to know that using forums to ask for help has been done in the GNU/Linux community since day one. This is not cheating, this is asking for help. Furthermore, much respect to the OP for clearly stating in the first post that this is a school project.
Best regards,
HMW
Thanks! It was not the teacher actually. Just someone in my class trolling.. But if it was - thanks for pointing out that this isn't cheating. We are looking for help to learn and to be as well prepared for exams as possible.
From what I understood we forgot to write parameters. $# for every number up to 9?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.