Skip to contentSkip to conversation

shell: Fix handling default parameters in tst_mkfs()

PATCH New Petr Vorel 2 participants 4 messages Mar 27, 2019 – Apr 4, 2019

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 shell: Fix handling default parameters in tst_mkfs()

fixes regression when testing df01.sh

Dash does not like shifting more than possible:
/opt/ltp/testcases/bin/df01.sh: 291: shift: can't shift that many

Fixes 465faf47f ("shell: Use $TST_FS_TYPE and $TST_DEVICE in tst_mkfs()")

---
Hi,

don't like checking $# twice, but don't see right now way to do it simpler.

Sorry for introducing regression.

Kind regards,
Petr

---
 testcases/lib/tst_test.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
testcases/lib/tst_test.sh +2 -1
index af16ce1cf..d3905d378 100644
@@ -288,7 +288,8 @@ tst_mkfs()
 {
 	local fs_type=${1:-$TST_FS_TYPE}
 	local device=${2:-$TST_DEVICE}
-	shift 2
+	[ $# -eq 1 ] && shift 1
+	[ $# -ge 2 ] && shift 2
 	local fs_opts="$@"
 
 	if [ -z "$fs_type" ]; then
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/1 shell: Fix handling default parameters in tst_mkfs()

Hi!

Quoted 5 lines

fixes regression when testing df01.sh

Dash does not like shifting more than possible:
/opt/ltp/testcases/bin/df01.sh: 291: shift: can't shift that many

Quoted 8 lines
Fixes 465faf47f ("shell: Use $TST_FS_TYPE and $TST_DEVICE in tst_mkfs()")

---
Hi,

don't like checking $# twice, but don't see right now way to do it simpler.

We can do the same thing twice as well, which may be a bit more readable:

	[ $# -ge 1 ] && shift
	[ $# -ge 1 ] && shift
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#2 lore raw

PATCH 1/1 shell: Fix handling default parameters in tst_mkfs()

Hi Cyril,

Quoted 5 lines

We can do the same thing twice as well, which may be a bit more readable:

	[ $# -ge 1 ] && shift
	[ $# -ge 1 ] && shift

I'd prefer my way, as this looks like entered twice by accident. But you chose the variant :).

Kind regards,
Petr

author
#3 lore raw

PATCH 1/1 shell: Fix handling default parameters in tst_mkfs()

In reply to Cyril Hrubis

Hi Cyril,

Quoted 5 lines

We can do the same thing twice as well, which may be a bit more readable:

	[ $# -ge 1 ] && shift
	[ $# -ge 1 ] && shift

Merged your variant. It's really more readable.
Thanks!

Kind regards,
Petr