This website is released under |
A Quick Introduction to Bash ProgrammingPreliminary Remarks
Example 1ProblemLet’s start with the classic «Hello, World» program. Solution#!/bin/bash echo "Hello, Mars!" Discussion
Exercices
Example 2ProblemWrite a program that calculates the MD5 checksums for each frame in a file, by using the Solution#!/usr/bin/env bash input_file="$1" ffmpeg -i "$input_file" -f framemd5 "${input_file}_md5.txt" DiscussionThis specific FFmpeg command is to consider as a placeholder for almost any FFmpeg command we have seen during the workshop. Exercices
Example 3ProblemModify the program of example 2 in order to process all the files inside a folder. Solution#!/usr/bin/env bash path_to_folder="$1" files_in_folder="$(ls "$path_to_folder")" for input_file in $files_in_folder; do path_to_file="$path_to_folder/$input_file" ffmpeg -i "$path_to_file" -f framemd5 "${path_to_file}_md5.txt" done DiscussionEach Bash command is a line of code. If for the readability of the code you wish to have more than one command in the same line, then they have to be divided by a semicolon ( Example 4ProblemModify the program of example 3 to process all the audio-visual files inside a folder, but not other kinds of files. Example 5ProblemMake the program of example 4 interactive and check that the passed parameters are valid ones. Example 6ProblemAdd options to the program of example 4, and in particular a help menu. 2020-04-06 |