Skip to contentSkip to conversation

patch to fix bashism

PATCH Han Boetes 2 participants 2 messages Apr 8, 2005 – Apr 9, 2005

lore
Share & tools
lore

Han Boetes

author
#0 lore raw

Hi,

This patch fixes a three bashisms in
scripts/gen_initramfs_list.sh;

I'm not sure of the intention of the second change (local name=...). So it's very well possible that:

+ local name="${location%/$srcdir}"

is more appropriate.

gen_initramfs_list.sh renamed from gen_initramfs_list.sh.orig +8 -5
@@ -1,4 +1,7 @@
-#!/bin/bash
+#!/bin/sh
+
+# script is sourced, the shebang is ignored.
+
 # Copyright (C) Martin Schlemmer <[email protected]>
 # Released under the terms of the GNU GPL
 #
@@ -56,9 +59,9 @@
 
 parse() {
 	local location="$1"
-	local name="${location/${srcdir}//}"
+	local name="${location#$srcdir/}"
 	# change '//' into '/'
-	name="${name//\/\///}"
+	name=`echo $name|sed -e 's|//|/|g'`
 	local mode="$2"
 	local uid="$3"
 	local gid="$4"
@@ -68,8 +71,8 @@
 	[ "$gid" -eq "$root_gid" ] && gid=0
 	local str="${mode} ${uid} ${gid}"
 
-	[ "${ftype}" == "invalid" ] && return 0
-	[ "${location}" == "${srcdir}" ] && return 0
+	[ "${ftype}" = "invalid" ] && return 0
+	[ "${location}" = "${srcdir}" ] && return 0
 
 	case "${ftype}" in
 		"file")

# Han

#1 lore raw
Quoted 11 lines · Han Boetes

Hi,

This patch fixes a three bashisms in
scripts/gen_initramfs_list.sh;

I'm not sure of the intention of the second change (local name=...). So it's very well possible that:

+ local name="${location%/$srcdir}"

is more appropriate.

This patch is not going to work; local is a bash:ism too, hence this will fail when /bin/sh is a more strict POSIX-shell. However, it is quite likely that the use of local is merely due to the (totally correct) instinct of always limiting the scope of variables. Most scripts that I've POSIX-fixed so far could just have the local removed with no bad effects.

Quoted 12 lines
gen_initramfs_list.sh renamed from gen_initramfs_list.sh.orig +4 -1
@@ -1,4 +1,7 @@
-#!/bin/bash
+#!/bin/sh
+
+# script is sourced, the shebang is ignored.
+
 # Copyright (C) Martin Schlemmer <[email protected]>
 # Released under the terms of the GNU GPL
 #

gen_initramfs_list.sh line 64

Quoted 8 lines
gen_initramfs_list.sh renamed from gen_initramfs_list.sh.orig +2 -2
@@ -56,9 +59,9 @@
 
 parse() {
 	local location="$1"
-	local name="${location/${srcdir}//}"
+	local name="${location#$srcdir/}"
 	# change '//' into '/'
-	name="${name//\/\///}"
+	name=`echo $name|sed -e 's|//|/|g'`

Using $(...) instead of ... helps readability quite a lot for things like this...

[snip]

Regards: David Weinehall

Signature · 3 lines
 /) David Weinehall <[email protected]> /) Northern lights wander      (\
//  Maintainer of the v2.0 kernel   //  Dance across the winter sky //
\)  http://www.acc.umu.se/~tao/    (/   Full colour fire           (/