Random Linux+ Question #39

Discussion in 'Linux+' started by tripwire45, Jul 20, 2005.

  1. tripwire45
    Honorary Member

    tripwire45 Zettabyte Poster

    13,493
    180
    287
    You want to link one command such that depending if the first command is executed correctly or not, the second command will execute. In this case, you want to cat (read) a text file named "aardvark" and if it doesn't exist (returns an error) then you want to execute the "ls -al" command piped to the "more" command so you can search the directory. Of the selections below, which one will produce the desired result? Choose only one answer.

    1. cat aardvark !! ls -al | more
    2. cat aardvark || ls -al | more
    3. cat aardvark && ls -al | more
    4. (cat aardvark ##) ls -al | more
    5. [cat aardvark $$] ls -al | more
    6. {cat aardvark %%} ls -al | more

    Answer later.
     
    Certifications: A+ and Network+
  2. Jellyman_4eva

    Jellyman_4eva Byte Poster

    213
    4
    34
    OK,

    Its either 2 or 3, and I shall say I have more confidence in number 2 being the right answer in this case, and 3 is used for when the first command is succesful!
     
    Certifications: MCDST, MCITP-EDST/EDA/EA/SA/ MCSA 2K3/2K8, MCSE+M 2K3/2K8, ISA/TMG, VCP3/4, CCNA, Exchange, SQL, Citrix, A+, N+, L+, Sec+, Ser+, JNCIA-SSL, JNCIS-SSL
    WIP: Lots
  3. tripwire45
    Honorary Member

    tripwire45 Zettabyte Poster

    13,493
    180
    287
    The correct answer is 3. The syntax command1 && command2 will execute as if the first command returns an error, the second command will execute. I can see why you were comfused between 2 and 3. The syntax for #2 command1 || [/i]command2 will execute as if the first command executes properly then command 2 will also execute.
     
    Certifications: A+ and Network+

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.