COP 2344 (Shell Scripting) Project #1 (Solution)
Basic Commands

 

Due: by the start of class on the date shown on the syllabus

Description:

Do all the exercises from your textbook, chapter 2 (pages 38–39).

Solutions

Chapter 2 (pages 38–39) questions:

  1. Given the following files in your current directory:
        feb96 jan12.02 jan19.02 jan26.02 jan5.02 jan95 jan96 jan97 jan98 mar98 memo1 memo10 memo2 memo2.sv
    

    What would be the output of the following commands?  (Note, ranges in globs are guaranteed to work properly only in the POSIX locale, so assume that.)

    echo *
    feb96 jan12.02 jan19.02 jan26.02 jan5.02 jan95 jan96 jan97 jan98 mar98 memo1 memo10 memo2 memo2.sv
    echo *[!0-9]
    memo2.sv
    echo m[a-df-z]*
    mar98
    echo [A-Z]*
    [A-Z]*
    echo jan*
    jan12.02 jan19.02 jan26.02 jan5.02 jan95 jan96 jan97 jan98
    echo *.*
    jan12.02 jan19.02 jan26.02 jan5.02 memo2.sv
    echo ?????
    feb96 jan95 jan96 jan97 jan08 memo1 memo2
    echo *02
    jan12.02 jan19.02 jan26.02 jan5.02
    echo jan?? feb?? mar??
    jan95 jan96 jan97 jan98 feb96 mar98
    echo [fjm][ae][bnr]*
    feb96 jan12.02 jan19.02 jan26.02 jan5.02 jan95 jan96 jan97 jan98 mar98
  2. What is the effect of the following:
    ls | wc -l
    Shows count of non-hidden files in the current directory.
    rm ???
    Delete all 3 letter file names.
    who | wc -l
    Shows count of current logins.
    mv progs/* /users/steve/backup
    Moves files from ./progs/ to /users/steve/backup (presumably a directory).  Note that if “backup” isn't a directory, this will still work if the glob “progs/*” expands to just one file.
    ls *.c | wc -l
    Shows count of files in cwd that end in ".c".
    rm *.o
    Delete all files in cwd that end in ".o".
    who | sort
    Show current logins, alphabetically.
    cd; pwd
    Change to and show the user's home directory.
    cp memo1 ..
    Copy ./memo1 to the parent directory.
    plotdata 2>errors &
    Run the plotdata command (whatever that is) in the background, redirecting errors to the file "./errors".