LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   URGENT!!!! Anyone knows how to programme in linux? (https://www.linuxquestions.org/questions/linux-newbie-8/urgent-anyone-knows-how-to-programme-in-linux-4175527133/)

grail 12-02-2014 09:14 PM

Ok ... it seems we jumped the gun.

Try reading something like http://tldp.org/LDP/abs/html/

Specifically look for #,## and %,%% and also ${#variable_name}:
Code:

var='one two three four'

f_pos="${var%f*}f"

len=${#f_pos}

echo $len

This would show you which position the letter 'f' is at in the original string

jeffrey1289 12-02-2014 09:28 PM

I don't have a textbook....

grail 12-02-2014 10:24 PM

So you are doing a course and there is no textbook, course notes or online material provided ... how very strange. In this case I would probably suggest changing to a course / school where it is reputable and actually
provides the material required for learning.

rknichols 12-03-2014 04:02 PM

I agree it doesn't seem like a very well organized course, and your code samples to date seem to indicate that you've just jumped into the deep end of the pool, e.g.:
Quote:

Originally Posted by jeffrey1289 (Post 5278506)
Code:


    if length "$line" | grep '^[^;]' > max
      max=length "$line" | grep '^[^;]'


That is so far removed from any syntax I know that I can't even tell what language it's supposed to be.

Just some useful hints:
Code:

Matcher="^([^;].*[^ ]) *(;.*)"    # A regular expression to match a string beginning with something other
                                  #  than a semicolon, followed by a string of any characters up through
                                  #  the last non-space character that is then followed by any spaces and
                                  #  a semicolon then followed by any number of characters.  (Whew!)
if [[ $Line =~ $Matcher ]]; then  # If line contains both code and comment
    Code="${BASH_REMATCH[1]}"      # First parenthesized segment is just the code w/o trailing spaces
    Comment="${BASH_REMATCH[2]}"  # Second parenthesized segment is the comment
    Code_length=${#Code}          # Length of $Code
    .
    .
    .
fi



All times are GMT -5. The time now is 08:13 AM.