1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Random Linux+ Question March 27

Discussion in 'Linux+' started by tripwire45, Mar 28, 2006.

  1. tripwire45
    Honorary Member

    tripwire45 Zettabyte Poster

    13,493
    179
    287
    You want to print the contents of the /etc/profile file on your linux computer. In addition, you want to number each line and double-space the lines. You also want the document you are printing to have the header "/etc/profile". Which command or commands below that will prepare this file for printing and accomplish all your goals? Select 2 answers.

    1. pr -d --header=/etc/profile /etc/profile | lpr
    2. pr -dnh /etc/profile /etc/profile | lpr
    3. cat -n /etc/profile | pr -dh /etc/profile | lpr
    4. cat /etc/profile | pr -ndh /etc/profile | lpr
     
    Certifications: A+ and Network+
  2. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    I don't know which one of those will work, but the following does:
    [HIDE]
    Code:
    cat -n /etc/profile | pr -d --header=/etc/profile | lpr
    I'd have to say that it's probably 3 by what I did above.[/HIDE]
     
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1
  3. simongrahamuk
    Honorary Member

    simongrahamuk Hmmmmmmm?

    6,199
    125
    199
    [HIDE]Erm..... Number 1? Complete guess though.[/HIDE]
     
  4. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,623
    115
    224
    [HIDE]Actualy - only one will work - 3. If one of the others works on a Linux distrib then its param parsing is broken! However - I can only test this on FreeBSD as yet.[/HIDE]

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  5. Dosh

    Dosh Bit Poster

    22
    1
    5
    [HIDE]answer 2[/HIDE]
     
  6. tripwire45
    Honorary Member

    tripwire45 Zettabyte Poster

    13,493
    179
    287
    Answer time. Answers 2 and 3 are correct although 3 is probably the best choice based on output. Here's what happens when you input the solution in answer 2.:
    Code:
    2004-11-10 09:23                   /etc/profile                   Page 1
    
    
        1h# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
    
        2h# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
    
        3h
    
        4hif [ "`id -u`" -eq 0 ]; then
    
        5h  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"
    
        6helse
    
        7h  PATH="/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games"
    
        8hfi
    
        9h
    
       10hif [ "$PS1" ]; then
    
       11h  if [ "$BASH" ]; then
    
       12h    PS1='\u@\h:\w\$ '
    
       13h  else
    
       14h    if [ "`id -u`" -eq 0 ]; then
    
       15h      PS1='# '
    
       16h    else
    
       17h      PS1='$ '
    
       18h    fi
    
       19h  fi
    
       20hfi
    
       21h
    
       22hexport PATH
    
       23h
    
       24humask 022
    Here's the output from answer 3.:
    Code:
    2006-03-28 16:10                   /etc/profile                   Page 1
    
    
         1  # /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
    
         2  # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
    
         3
    
         4  if [ "`id -u`" -eq 0 ]; then
    
         5    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"
    
         6  else
    
         7    PATH="/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games"
    
         8  fi
    
         9
    
        10  if [ "$PS1" ]; then
    
        11    if [ "$BASH" ]; then
    
        12      PS1='\u@\h:\w\$ '
    
        13    else
    
        14      if [ "`id -u`" -eq 0 ]; then
    
        15        PS1='# '
    
        16      else
    
        17        PS1='$ '
    
        18      fi
    
        19    fi
    
        20  fi
    
        21
    
        22  export PATH
    
        23
    
        24  umask 022
    Similar but not quite the same, yet both within the parameters set down in the question. Yes, Freddy, you can either use the -h or the --header= options and they'll work the same. :)
     
    Certifications: A+ and Network+
  7. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    I realize that, but I'd still use the --header=header_name syntax. It's much easier for someone, anyone, well, myself, to see what I did six months or a year later when looking at a script I'd written previously.
     
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1
  8. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,623
    115
    224
    But note the formatting error with option 2 - I got the same which is why I rejected it.

    In actual fact it is (IMHO) wrong to use two options-with-parameters like that. They need to be separated.
    This is why the format breaks.

    :biggrin

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  9. tripwire45
    Honorary Member

    tripwire45 Zettabyte Poster

    13,493
    179
    287
    Yep. Agreed, guys. I was originally going to go with only one correct answer (#3) but number 2 seemed close enough to fit the bill. 3 is the better option, tho. :wink:
     
    Certifications: A+ and Network+

Share This Page

Loading...