Skip to content

Instantly share code, notes, and snippets.

@marcelomgarcia
Created July 4, 2019 13:03
Show Gist options
  • Save marcelomgarcia/8d0677dc42f1537f2dda64701790f1ed to your computer and use it in GitHub Desktop.
Save marcelomgarcia/8d0677dc42f1537f2dda64701790f1ed to your computer and use it in GitHub Desktop.
Split variables in format "WWxHH" "WW" and "HH" (width and height) in Bash.
#!/usr/bin/env bash
# Split the values passed as wwwXhhh in width and height
#
function wh_vals {
# Convert upper 'X' to lower 'x' so the 'cut' command works.
size="$(tr '[:upper:]' '[:lower:]' <<<"$1")"
width="$(cut -d'x' -f1 <<<"$size")"
height="$(cut -d'x' -f2 <<<"$size")"
}
mysize="$1"
wh_vals $mysize
echo $width
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment