Skip to content

Commit

Permalink
Replace 'tr' with bash string manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
zdykstra committed Feb 16, 2022
1 parent 8916a10 commit dbd9642
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions zfsbootmenu/install-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ zfsbootmenu_essential_binaries=(
"sed"
"grep"
"tail"
"tr"
"tac"
"blkid"
"awk"
Expand Down Expand Up @@ -73,7 +72,8 @@ create_zbm_conf() {
# Create core ZBM configuration file

local endian ival
ival="$( echo -n 3 | od -tx2 -N2 -An | tr -d '[:space:]' )"
ival="$( echo -n 3 | od -tx2 -N2 -An )"
ival="${ival//[[:space:]]/}"
if [ "${ival}" = "3300" ]; then
endian="be"
else
Expand Down
3 changes: 2 additions & 1 deletion zfsbootmenu/lib/zfsbootmenu-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ get_spl_hostid() {

# Otherwise look to /etc/hostid, if possible
if [ -r /etc/hostid ] && command -v od >/dev/null 2>&1; then
spl_hostid="$( od -tx4 -N4 -An /etc/hostid 2>/dev/null | tr -d '[:space:]' )"
spl_hostid="$( od -tx4 -N4 -An /etc/hostid 2>/dev/null )"
spl_hostid="${spl_hostid//[[:space:]]/}"
if [ -n "${spl_hostid}" ]; then
zdebug "hostid from /etc/hostid: ${spl_hostid}"
echo -n "0x${spl_hostid}"
Expand Down
5 changes: 4 additions & 1 deletion zfsbootmenu/lib/zfsbootmenu-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,10 @@ snapshot_dispatcher() {

[ -n "${user_input}" ] || return

valid_name=$( echo "${user_input}" | tr -c -d 'a-zA-Z0-9-_.:' )
shopt -s extglob
valid_name="${user_input//+([!a-zA-Z0-9-_.:])/}"
shopt -u extglob

if [[ "${user_input}" != "${valid_name}" ]]; then
echo "${user_input} is invalid, ${valid_name} can be used"
pre_populated="${valid_name}"
Expand Down

0 comments on commit dbd9642

Please sign in to comment.