Skip to content

Instantly share code, notes, and snippets.

@alifahrri
Last active November 21, 2019 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alifahrri/33db9c3f6d759aef3141c8d0b2220b3a to your computer and use it in GitHub Desktop.
Save alifahrri/33db9c3f6d759aef3141c8d0b2220b3a to your computer and use it in GitHub Desktop.
  • Directory
#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
  • Arguments
#!/bin/bash
echo "First arg: $1"
echo "Second arg: $2"
  • Check if string is empty
if [ ! -z "$str" -a "$str" != " " ]; then
        echo "Str is not null or space"
fi
  • Argument parsing
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"

case $key in
    -e|--extension)
    EXTENSION="$2"
    shift # past argument
    shift # past value
    ;;
    -s|--searchpath)
    SEARCHPATH="$2"
    shift # past argument
    shift # past value
    ;;
    -l|--lib)
    LIBPATH="$2"
    shift # past argument
    shift # past value
    ;;
    --default)
    DEFAULT=YES
    shift # past argument
    ;;
    *)    # unknown option
    POSITIONAL+=("$1") # save it in an array for later
    shift # past argument
    ;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
  • loop directory
for entry in "$SEARCHPATH"/*
do
  echo $entry
  filename=${entry##*/}
  python3 example1.py --model $MODEL --image $entry --output $OUTPUT/$filename || exit 1 # exit 1 if failure
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment