Skip to content

Commit dbd9642

Browse files
committed
Replace 'tr' with bash string manipulation
1 parent 8916a10 commit dbd9642

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

zfsbootmenu/install-helpers.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ zfsbootmenu_essential_binaries=(
2020
"sed"
2121
"grep"
2222
"tail"
23-
"tr"
2423
"tac"
2524
"blkid"
2625
"awk"
@@ -73,7 +72,8 @@ create_zbm_conf() {
7372
# Create core ZBM configuration file
7473

7574
local endian ival
76-
ival="$( echo -n 3 | od -tx2 -N2 -An | tr -d '[:space:]' )"
75+
ival="$( echo -n 3 | od -tx2 -N2 -An )"
76+
ival="${ival//[[:space:]]/}"
7777
if [ "${ival}" = "3300" ]; then
7878
endian="be"
7979
else

zfsbootmenu/lib/zfsbootmenu-core.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ get_spl_hostid() {
118118

119119
# Otherwise look to /etc/hostid, if possible
120120
if [ -r /etc/hostid ] && command -v od >/dev/null 2>&1; then
121-
spl_hostid="$( od -tx4 -N4 -An /etc/hostid 2>/dev/null | tr -d '[:space:]' )"
121+
spl_hostid="$( od -tx4 -N4 -An /etc/hostid 2>/dev/null )"
122+
spl_hostid="${spl_hostid//[[:space:]]/}"
122123
if [ -n "${spl_hostid}" ]; then
123124
zdebug "hostid from /etc/hostid: ${spl_hostid}"
124125
echo -n "0x${spl_hostid}"

zfsbootmenu/lib/zfsbootmenu-lib.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,10 @@ snapshot_dispatcher() {
404404

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

407-
valid_name=$( echo "${user_input}" | tr -c -d 'a-zA-Z0-9-_.:' )
407+
shopt -s extglob
408+
valid_name="${user_input//+([!a-zA-Z0-9-_.:])/}"
409+
shopt -u extglob
410+
408411
if [[ "${user_input}" != "${valid_name}" ]]; then
409412
echo "${user_input} is invalid, ${valid_name} can be used"
410413
pre_populated="${valid_name}"

0 commit comments

Comments
 (0)