Skip to content

Instantly share code, notes, and snippets.

@roblogic
Created March 26, 2019 15:47
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 roblogic/2b81e4e84b01bd925ee7aaf26ae8bf34 to your computer and use it in GitHub Desktop.
Save roblogic/2b81e4e84b01bd925ee7aaf26ae8bf34 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/bash
for l in "$@";do # for each arg
d=${#l}
for((i=0;i<d;i++)){
s="${l: -i}" # take i-length suffix, s
a+=( "$s" )
for((j=1;j<${#s};j++)){
a+=( "${s:0:j}" ) # take j-length prefix of s
}
}
done
for m in "${a[@]}";do
k=0
for n in "$@";do
[[ $n =~ $m ]]&&{ ((k++));}
done
[ $k = $# ]&&{ b+=( "$m" );} # store the strings that match all inputs
done
for e in "${b[@]}";do
[ ${#e} -gt ${#f} ]&&{ f="$e";}
done
echo "$f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment