Skip to content

Latest commit

 

History

History
66 lines (52 loc) · 2.57 KB

File metadata and controls

66 lines (52 loc) · 2.57 KB

BASH-amo le mani

These are some exercises I found online.
At this link there you can find a super bash course where I got some of these exercises.
DOI

Useful Links

Write a script seq <start> <step> <end>

  • if one argument is provided seq <end> will print from 1 to end
  • if two arguments are provided seq <start> <end> will print from start to end
  • if three arguments are provided seq <start> <step> <end> will print from start to end every step

seq 1 4 13 should output:

1
5
9
13

Write a script create.sh <i> <j> <file>:

  • create directories named 1, 2, ..., i
  • use touch to put empty files named 1 till j in each of these directories
  • print an error if a negative value is provided fo i or j
  • if any of the files exist, the script should exit with an error
  • provide help if one of the args is -h, then exit the script
  • if the third argument is a file, the script should copy this file to all locations instead of createing empty files with touch

Write a script match_patterns.sh <path> <pat1> <pat2> <pat3>:

  • it should find the patterns provided in the file path
  • it should display for each pattern the number of matches followed by the line numbers the matches did occur

Create a script ps_monitor.sh <N>:

  • if no argument are passed it should show the processes of all users (including those without a controlling terminal) with information on the username and start time;
  • if an integer (N) is passed, it should show the first N processes

SUGGESTION: use ps command

Create a script that accept two args with the following sintax:
./lines_counter.sh <directory> [up|down]
The script need to show the files present in the directory with the relative number of lines present in each file, sorted in ascendig or descending order.

NOTES:

  • check if first argument is a directory
  • check if second argument is 'up' or 'down'

Create a script as follow:
./backup.sh <name> <backupName>

If name is a directory:

  1. make a directory in the current dir name_backupName
  2. recursively copy the content of name into it

If name is a file make 5 copies of it with the following sintax:
<name>*i<backupName>

NOTE: consider only directories and files inside the current directory.