User Tools

Site Tools


labs:bash

Bash & Git

In this fachpraktikum you are supposed to see the basic of bash. The goal is that you know the type of problems for which it is the right tool. You will work on a command line. Despite the ancient feeling, a lot of problems can be solved much more efficiently than with a GUI. For every command, you can find help using man <command> (you can leave this screen by pressing q). We also expect you to use Google whenever you encounter a problem. Have a look at this Cheat Sheet. It contains most of the commands you will need (and quite a lot that you don't). You can use redirects to write the output of a program into a file.

We provide you with scripts for the first two exercises (exercise1.sh/exercise2.sh) that check your results.

Exercise 1

As a first task, please checkout the necessary files from your git repository (you will have to install git first). You can find it under 10.0.0.1:/opt/git/ti2fp. The username is git; the password is ti2lab. To avoid conflicts with your fellow students, please create a folder with the name of your nethz account and copy the files into this folder. You can now create a new repository in this folder. This will allow you to undo any mistakes you make. A short (and simple) introduction can be found here. We urge you to commit your changes after you have successfully solved an exercise.

  1. Print the content of msft.csv on the terminal.
  2. Create a file called allTheData.csv that contains every line from every *.csv file in the main folder.
  3. Unfortunately, your colleague, who created these files, did not follow the standard you agreed upon. Instead of a ; he used a # to separate the columns. Fix his mistake in allTheData.csv.
  4. Count the number of lines in allTheData.csv write it into numberOfLines.txt.
  5. Go to the folder csv-Files. In this folder there are dozens of csv files (in subfolders). Write the name of every *.csv file (including the path starting from the folder csv-Files) into csvFilesList.txt.
  6. Write the content of all these files into allCSVFilesContent.txt.
  7. Go to the folder src/core. Print every line that contains the string author or Author.
  8. Append the string // Author: ETH Zurich to every *.java file in this directory.
  9. Print every filename that contains the string // Author: University of Zurich.
  10. Delete those files.
  11. Go to the folder src/utils. Print every file in this folder that does not contain DO NOT DELETE.
  12. Delete those files.

Exercise 2

Some bash commands accept only parameters as input. But some also accept input from stdin. Have a look at Pipes. In this exercise, we will explore a few examples. Please change to the folder exercise2.

  1. Write every line that contains import (note the space), but not bitcoinj in the folder src/core in a file called all_the_imports.txt.
  2. Count the total number of lines that contain “import” in every java file in src/core and write it into importLine.txt
  3. You know now how many lines there are. But you (should have) noticed that quite a few lines appear more than once. Which line appears the most? Write this line (without spaces in the beginning) into mostImported.txt.
  4. The file allSrc.txt (in the folder src) contains a list of files. Write every line of these files that contain the word static into the file static.txt.

Exercise 3

In this exercise we advise you to write bash scripts, i.e., *.sh files. They will make life a bit easier. You can find some basic information here and here.

  1. You work together with a colleague who uses Windows. Thus, he cannot checkout the repository (because the files in the folder files with dots contain a :). Replace all the : with _.
  2. Write a script that prints out is running if looper is running and is not running otherwise. Note that this process is currently not running.
  3. Update your script such that it starts looper if it is not running.
  4. Update your script such that it continuously monitors looper.
  5. Update your script such that it accepts the names of several programs as parameter, i.e., ./yourScript.sh looper backGround should work.
labs/bash.txt · Last modified: 2020/08/31 21:03 (external edit)