====== 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 '' (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 [[http://cli.learncodethehardway.org/bash_cheat_sheet.pdf|Cheat Sheet]]. It contains most of the commands you will need (and quite a lot that you don't). You can use [[http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html|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 [[http://rogerdudler.github.io/git-guide/|here]]. We urge you to commit your changes after you have successfully solved an exercise. - Print the content of ''msft.csv'' on the terminal. - Create a file called ''allTheData.csv'' that contains every line from every ''*.csv'' file in the main folder. - 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''. - Count the number of lines in ''allTheData.csv'' write it into ''numberOfLines.txt''. - 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''. - Write the content of all these files into ''allCSVFilesContent.txt''. - Go to the folder ''src/core''. Print every line that contains the string ''author'' or ''Author''. - Append the string ''%%//%% Author: ETH Zurich'' to every ''*.java'' file in this directory. - Print every **filename** that contains the string ''%%//%% Author: University of Zurich''. - Delete those files. - Go to the folder ''src/utils''. Print every file in this folder that does not contain ''DO NOT DELETE''. - Delete those files. ===== Exercise 2 ===== Some bash commands accept only parameters as input. But some also accept input from stdin. Have a look at [[http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html|Pipes]]. In this exercise, we will explore a few examples. Please change to the folder ''exercise2''. - 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''. - Count the total number of lines that contain "import" in every java file in src/core and write it into ''importLine.txt'' - 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''. - 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 [[http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-5.html|here]] and [[http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html|here]]. - 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 ''_''. - 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. - Update your script such that it starts ''looper'' if it is not running. - Update your script such that it continuously monitors ''looper''. - Update your script such that it accepts the names of several programs as parameter, i.e., ''./yourScript.sh looper backGround'' should work.