Skip to content

Commit

Permalink
Merge pull request #21 from nestauk/add_scripting
Browse files Browse the repository at this point in the history
Add files for a shell scripting session
  • Loading branch information
instantiator committed Feb 21, 2024
2 parents a54bf6d + 8b229ca commit 817b0e4
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ __pycache__/
.ipynb_checkpoints/
*/data/*

*.env
*.env
.metaflow
47 changes: 47 additions & 0 deletions shell_scripting/summarise-sln.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

set -e
set -o pipefail

usage() {
cat << EOF
Summarise the files in a directory
Options:
-i <path> --input-directory <path> The input directory
-h --help Prints this help message and exits
EOF
}

while [ -n "$1" ]; do
case $1 in
-i | --input-directory)
shift
IN_DIR=$1
;;
-h | --help)
usage
exit 0
;;
*)
echo -e "Unknown option $1...\n"
usage
exit 1
;;
esac
shift
done

if [ -z "$IN_DIR" ]; then
echo "Please provide an input directory."
usage
exit 1
fi

for FILE in $IN_DIR/*; do
[ -f "$FILE" ] || break
BYTES=$(wc -c < "$FILE")
echo "$(file $FILE) - has: $(echo $BYTES | tr -d ' ') bytes"
done

46 changes: 46 additions & 0 deletions shell_scripting/summarise.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

set -e
set -o pipefail

usage() {
cat << EOF
Summarise the files in a directory
Options:
-i <path> --input-directory <path> The input directory
-h --help Prints this help message and exits
EOF
}

while [ -n "$1" ]; do
case $1 in
-i | --input-directory)
shift
IN_DIR=$1
;;
-h | --help)
usage
exit 0
;;
*)
echo -e "Unknown option $1...\n"
usage
exit 1
;;
esac
shift
done

if [ -z "$IN_DIR" ]; then
echo "Please provide an input directory."
usage
exit 1
fi

for FILE in $IN_DIR/*; do
[ -f "$FILE" ] || break
BYTES=$(wc -c < "$FILE")
echo "$(file $FILE) - has: $BYTES bytes"
done

0 comments on commit 817b0e4

Please sign in to comment.