Skip to content

Instantly share code, notes, and snippets.

@loloicci
Last active February 26, 2019 07:44
Show Gist options
  • Save loloicci/f54640c072ecbb059738f4c78f9a66bf to your computer and use it in GitHub Desktop.
Save loloicci/f54640c072ecbb059738f4c78f9a66bf to your computer and use it in GitHub Desktop.
an example to use commas as delimiters for 'for' in bash.
#!/bin/bash
CMD_LINE="ro root=/dev/example1,/dev/example2 splash quiet"
for CMD_PARAM in ${CMD_LINE}; do
case ${CMD_PARAM} in
root=*)
ROOT_DEV=${CMD_PARAM#root=}
;;
*)
echo "parameters other than 'root': ${CMD_PARAM}"
;;
esac
done
echo "==== ROOT_DEV ===="
echo ${ROOT_DEV}
echo "==== DEVICES ===="
################ TECH HERE ################
# replace comma with space to split
for DEV in ${ROOT_DEV//,/ }; do
echo ${DEV}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment