Results 1 to 7 of 7

Thread: What does #Source: mean/do?

  1. #1
    Join Date
    Feb 2013
    Beans
    27

    What does #Source: mean/do?

    Some example scripts I see on the top after #!/bin/bash I see #Source: ......
    The .... contains just random words. I suppose they are other script names.

    Thanks

  2. #2
    Join Date
    Jun 2007
    Location
    Porirua, New Zealand
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: What does #Source: mean/do?

    Sometimes it depends on the context. Do you have an example?
    Forum DOs and DON'Ts
    Please use CODE tags - Including your email address in a post is not recommended
    Never assume that the information provided by Dr Google is up-to-date or relevant.

  3. #3
    Join Date
    Feb 2013
    Beans
    27

    Re: What does #Source: mean/do?

    I have a hunch that it means run this script first and use the variables but when I tried an example of my own it didn't work. Like I made a script with variables x=100. I made another script with variable y with value 50. And in that script I said if [ $x -le $y ] ........
    But when I ran the second script it says unary operator expected.

  4. #4
    Join Date
    Feb 2013
    Beans
    27

    Re: What does #Source: mean/do?

    This is one of the examples I'm studying from

    Code:
    #!/bin/bash
    #Source: countod
    #read in a number of strings from user (until
    #user enters  END  or end) and output the total
    #number of strings that are  files  & the total
    #number that are directories.
    #note: if the user enters more than one string on a line,
    # will get if [ -f str1 str2 etc ] bash syntax error
    
    
    typeset -i  ordfile=0
    typeset -i  dirfile=0
    
    
    while  [ true ]
    do
         echo  Enter a file name or  END to quit
         read filenam
         if  [ "$filenam" = "END" -o "$filenam" = "end" ]
         then
              break       #breaks out of the while loop, like in C
                      #continue statement also available
         fi
         if   [ -f  $filenam ]
         then
              ordfile=ordfile+1
         elif  [ -d $filenam ]
         then
              dirfile=dirfile+1
         fi
    done
    echo -e "The number of ordinary files:\t  $ordfile"
    echo -e "The number of directories:\t  $dirfile"
    exit 0
    I understand the body of the script I just don't understand the #Source: part...
    Last edited by lisati; March 10th, 2013 at 12:44 AM. Reason: Added [code] and [/code] to aid readbility

  5. #5
    Join Date
    Jun 2007
    Location
    Porirua, New Zealand
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: What does #Source: mean/do?

    Thread moved to Programming Talk.

    In a script such as the one you're studying, the "#" at the start of a line usually indicates a comment intended for use by a person rather than a computer.

    The first line, #!/bin/bash, is a special case, sometimes known as a "shebang", which helps the command line interpreter know how to interpret the contents of a file.

    I'm not familiar with "countod", it could refer to another script made by the person who produced the tutorial you are following.
    Forum DOs and DON'Ts
    Please use CODE tags - Including your email address in a post is not recommended
    Never assume that the information provided by Dr Google is up-to-date or relevant.

  6. #6
    Join Date
    May 2008
    Location
    SoCal
    Beans
    Hidden!
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: What does #Source: mean/do?

    This
    Code:
    #Source: countod
    #read in a number of strings from user (until
    #user enters  END  or end) and output the total
    #number of strings that are  files  & the total
    #number that are directories.
    #note: if the user enters more than one string on a line,
    # will get if [ -f str1 str2 etc ] bash syntax error
    Is just the comments about the script.

    The hash (#) causes the interpreter to ignore the line. In other words, it's a note for humans to read.

    Without the hashes:
    Source: countod
    read in a number of strings from user (until user enters END or end) and output the total number of strings that are files & the total number that are directories.
    note: if the user enters more than one string on a line, will get if [ -f str1 str2 etc ] bash syntax error
    Last edited by bab1; March 10th, 2013 at 12:57 AM.
    -BAB1

  7. #7
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: What does #Source: mean/do?

    Could you provide the source author and title of the book or post a link to the tutorial are you studying from?
    Last edited by sisco311; March 10th, 2013 at 02:00 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •