Created
December 2, 2019 09:00
-
-
Save imvaskii/ca7f964653bbb18712d3e381c403cea2 to your computer and use it in GitHub Desktop.
Bash script to repeat strings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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