Git Product home page Git Product logo

230-lab-bash-scripts's Introduction

COMPSCI 230 Computer Systems Principles

Simple Bash Scripts

In this lab we will look at an example of a bash script, and implement a simple one.

To start working on this lab you must be logged in to the Edlab and in your cs230 directory, or be in a similar environment on your local machine.

From this directory run the command:

$ git clone https://github.com/marcliberatore/230-lab-bash-scripts.git

to make a copy of this lab directory, or use Github Desktop, or download and decompress a zip file directly from Github to use locally (the green "Code" button has a "Download ZIP" option).

In order to be able to run the script split.sh, first do the following:

$ chmod +x split.sh

This will give split.sh "execute" permission for all users. Now you can run split.sh:

$ ./split.sh

After running the script, inspect the current directory and the directory and files the script created. What does this script do?

Open split.sh in your favorite text editor and examine the code. Try to understand what each line does as much as you can.

Look up the usage of printf with:

man printf

Recall that in Project 2, you were asked to read up on the documentation of printf with:

man 3 printf

What is the difference between these two man pages?

Modify one line in split.sh so that instead of file names

0.txt
1.txt
2.txt
...
10.txt
11.txt
12.txt
...
100.txt
101.txt
102.txt
...

we have

000.txt
001.txt
002.txt
...
010.txt
011.txt
012.txt
...
100.txt
101.txt
102.txt
...

Both man pages of printf will be helpful here.

Now let's implement a different script called change_permission.sh. By running change_permission.sh all files with extension .txt in a specified directory (which you will define in the script) should have read-only permission for all users. In addition, the string "***READ ONLY***" will be appended (use >>) to each .txt file as its last line.

Some hints:

  1. You will want to write a for loop that goes over every file with extension .txt. See here for more hints of what it might look like.

  2. Check the man page of chmod to see how to set file permissions.

  3. Read about option -l in the man page of ls to see how to display file permissions. (This is useful when you test your script.)

Visit the Gradescope assignment associated with this lab to complete the lab. You will be asked to answer questions associated with split.sh and to submit your change_permission.sh file.

230-lab-bash-scripts's People

Contributors

qy1417 avatar marcliberatore avatar sternj avatar

Stargazers

Anna Allen avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.