URGENT!!!! Anyone knows how to programme in linux?
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.
URGENT!!!! Anyone knows how to programme in linux?
I have an assignment that's due on Friday, which ask me to write a programme in linux to format the original source code. I think of it for so long, anyone can help me with it?
Assignment: Write a bash program to format the comments in an assembly language source file.
Conditions:
Comments begin with a ; (semicolon) and end with a newline. The source file will contain only printing characters, spaces, and newlines. It is not necessary to check for invalid input. Requirements:
Lines without comments should not be changed. Entire lines which are comments (begin with should not be changed. Lines containing both code and comments (; preceded by other characters) should have spaces inserted before the comments so all comments begin in the same column, at least 4 columns after the end of the longest code. Be sure your program includes all of the following:
comments with your name, the date, and the assignment comments or output with instructions for using the program prompts for any interactive inputs descriptive names and/or comments explaining variables & functions indentation of code blocks comments explaining any non-obvious control flow
The following is the code before and after. We should write a programme which reads a file contains the original code, and turn the original one to the formatted one, then output it on the screen. Please someone help me with it! Thank you!
I am having difficulties with calculating each line's length as it reads through, but it must read just up to the semicolon (, then add the differences between the longest line and the rest to all lines before the semicolon, so to do the format. This is what I have done up to now:
#!/bin/bash
echo "Start!"
echo "Please enter a file name: "
read name
cat $name| while read line; do
I was trying to cut the lines after the semicolon, and those lines start at the seconde line. The first line is just semicolon, and end with a new line, so all of the contents got deleted.
I was trying to do display the content that are not begin with a ;(semicolon), after the first line.
I type this:
echo "$line" | grep _C 1 '^[^[;]]'
it doesn't work. WHY?
As it is a bash assignment, I see no direct need to use other tools (not to say you couldn't)
So a few points of housekeeping first, seeing you are new:
1. Please read the LQ rules. Here you will see that no one will do your homework but we are happy to assist
2. The question is only urgent to you and as this is a community site it will not tend to yield you any quicker results
3. Please place all code and data in [code][/code] tags to maintain formatting and make it easier to read
So, on to your question. Like most first time programmers you are jumping in and have as yet not defined what you need your programme to do.
Having looked at the before and after code and reading the brief my thoughts would be:
1. Ignore all lines starting with a semi-colon
2. First pass of the file is needed to find what position is the greatest when it comes to semi-colons after code
3. Second pass would utilise number found in 2 to set all semi-colons after code, ie. add spaces prior to any that do not have semi-colon at desired position
How can I find the longest line before the semicolon? I tried use length but it just gives me the number, and I can't ignore the ;
what were the examples that were used in the textbook you are using ?
and there "SHOULD" be something like this in a end of the chapter exercise of that text book
remember software is NOT !!!! "route memorization "
it is DEDUCTIVE and symbolic logic
oops i let the cat out of the bag-- it is MATH!!!
How would "Sherlock Homes" solve a problem ?
then the logical steps that Sherlock used to get from point A to point D ?
Quote:
[code]
if length "$line" | grep '^[^;]' > max
max=length "$line" | grep '^[^;]'
[code]
you missed the close tag
in software
if you OPEN something you need to CLOSE that something
PHP Code:
[code] the copied code line3 line4 [/code]
you missed the closing "/" in the last tag
Code:
if length "$line" | grep '^[^;]' > max
max=length "$line" | grep '^[^;]'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.