bash Tracing Wierdness & Input Args

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

bash Tracing Wierdness & Input Args

#1 Post by s243a »

I added some "sh -x" to the top of some scripts (savefile to be attached shortly).and echo as debugging statments. I was trying to test out TazPup's OnDemand features and track down a "CWD" error.

I started the script something like this:

Code: Select all

sh -x
tazpup-ondemand 2>&1 | tee bla.txt
I noted that some of my debugging statments are showing up as input arguments in the "$@" variable. For instance I have

/usr/libexec/tazpkg

Code: Select all

#!/bin/sh -x
echo "entering /usr/libexec/tazpkg/get"
# TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
# get - TazPkg module
# Get package to the cache directory
echo "Entering /usr/libexec/tazpkg/get"
echo "sourcing /lib/libtaz.sh"
. /lib/libtaz.sh
echo "sourcing /usr/lib/slitaz/libpkg.sh"
. /usr/lib/slitaz/libpkg.sh
echo "sourcing /usr/libexec/tazpkg/getenv"
. /usr/libexec/tazpkg/getenv
echo "sourcing /usr/libexec/tazpkg/find-depends"
. /usr/libexec/tazpkg/find-depends
echo "sourcing finished"
/lib/libtaz.sh (lines 29 to 38

Code: Select all

# Parse cmdline options and store values in a variable.
for opt in "$@"; do
	opt_name="${opt%%=*}"; opt_name="$(echo -n "${opt_name#--}" | tr -c 'a-zA-Z0-9' '_')"
	case "$opt" in
		--[0-9]*=*)	export _$opt_name="${opt#*=}" ;;
		--[0-9]*)	export _$opt_name=yes ;;
		--*=*)		export  $opt_name="${opt#*=}" ;;
		--*)		export  $opt_name=yes ;;
	esac
done
producing the output:

Code: Select all

Entering /usr/libexec/tazpkg/get
sourcing /lib/libtaz.sh
sourcing /usr/lib/slitaz/libpkg.sh
sourcing /usr/libexec/tazpkg/getenv
sourcing /usr/libexec/tazpkg/find-depends
sourcing finished
/var/cache/tazpkg/5.0/packages/cups-pdf-2.6.1.tazpkg'
+ echo Entering /usr/libexec/tazpkg/intall
Entering /usr/libexec/tazpkg/intall
+ echo sourcing /lib/libtaz.sh
sourcing /lib/libtaz.sh
+ . /lib/libtaz.sh
+ . /usr/bin/gettext.sh
+ alias sed=busybox sed
+ lgettext Done
+ gettext -d slitaz-base Done
+ okmsg=Done
+ lgettext Failed
+ gettext -d slitaz-base Failed
+ ermsg=Failed
+ : 32
+ : 31
+ : 36
+ opt_name=entering /usr/libexec/tazpkg/get
It is though putting an echo statment directly under the shebang causes the input arguments to be replaced. Is this documented anywhere and what might cause this. I noticed that some places in the code there is an "unset IFS", I wonder if that has anything to do with this wierdness.

s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

#2 Post by s243a »

For security reasons I only attached the four files that I modified for tracing rather than the whole save file. I also manually created the folders so the premissions probably don't match.
Attachments
traceWierdness.tar.gz
(10.72 KiB) Downloaded 69 times

s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

#3 Post by s243a »

I tried adding a space after the shebang and also removed the "-x" in the shebang that I hadded in a few places. The latter is redundent since I'm using "set -x". My second hypothesis was that the tracing was getting captured in something like a pipe. I found the following:

Code: Select all

Command line: busybox basename entering /usr/libexec/tazpkg/get Entering /usr/libexec/tazpkg/get sourcing /lib/libtaz.sh sourcing /usr/lib/slitaz/libpkg.sh sourcing /usr/libexec/tazpkg/getenv sourcing /usr/libexec/tazpkg/find-depends sourcing finished /var/cache/tazpkg/5.0/packages/cups-2.0.2.tazpkg 

BusyBox v1.27.2 (2018-06-04 11:30:05 CEST) multi-call binary.

Usage: basename FILE [SUFFIX]

Strip directory path and .SUFFIX from FILE
cpio: short read
/usr/libexec/tazpkg/install: .: line 498: can't open '/tmp/tmp.xqOAJi/receipt'
+ process_list
+ debug '\nprocess_list()\n  list='\'''\'''
+ '[' -n '' ']'
+ local tmp_list pkg
+ '[' -z '' ']'
+ return
+ exit 0

/usr/libexec/lib/tazpkg/install (lines 481 502)

Code: Select all

[ -s "$UP_LIST" ] && sed -i "/^$PACKAGE\$/d" "$UP_LIST"
}

if [ "$(echo "$1" | cut -c 1-3)" != "../" ] && [ "$(echo "$1" | cut -c 1-2)" != "./" ] && [ "$(echo "$1" | cut -c 1)" != "/" ]; then
 xPKG="$(pwd)/$(basename $1)"
elif [ "$(echo "$1" | cut -c 1-2)" == "./" ] || [ "$(echo "$1" | cut -c 1-3)" == "../" ]; then
 xPKG="$(realpath "$1")"
else
 xPKG="$1"
fi

TMP_DIR=$(mktemp -d)

cd "$TMP_DIR"

cpio --quiet -i receipt < "$xPKG"

. $TMP_DIR/receipt

echo "Package name: $PACKAGE"

PACKAGE="$PACKAGE"
I wonder if cpio is capturing some of the trace output. I really don't understand cpio.

Post Reply