Created
October 15, 2020 16:06
-
-
Save fourdollars/af5c990874148915290046108afdc393 to your computer and use it in GitHub Desktop.
A Bash script to strip last N elements
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
#!/bin/bash | |
strip_last_n() | |
{ | |
n="$1" | |
shift | |
if [ "$n" -ge "$#" ]; then | |
return | |
else | |
len="$(($# - n))" | |
echo "${@:1:$len}" | |
fi | |
} | |
array=(0 1 2 3 4 5 6 7 8 9) | |
for i in {1..10}; do | |
echo "strip last $i" | |
strip_last_n "$i" "${array[@]}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment