Skip to content

Instantly share code, notes, and snippets.

@imvaskii
Created December 2, 2019 09:00
Show Gist options
  • Save imvaskii/ca7f964653bbb18712d3e381c403cea2 to your computer and use it in GitHub Desktop.
Save imvaskii/ca7f964653bbb18712d3e381c403cea2 to your computer and use it in GitHub Desktop.
Bash script to repeat strings.
#!/usr/bin/env bash
# Repeat String
#
# Usage repeat_string "-"
# repeat_string "-" 20
# ARG1: String
# ARG2: Count [optional]
repeat_string() {
sep=$1
count=$2
[ -z "$sep" ] && {
sep="="
}
[ -z "$count" ] && {
count=40
}
re='^[0-9]+$'
if ! [[ $count =~ $re ]]; then
echo "error: Not a number" >&2
exit 1
fi
echo
printf "=%.0s" $(seq "$count")
echo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment