I extracted part of a shell script into another shell script, and for some reason after calling the sub-script, command substitution stops working. I can’t imagine it’s something in the sub-script, but I can’t see what I’m doing wrong, either.
whether i do:
dirname "$0" # works
echo "`dirname "$0"`" # works
echo "$(dirname "$0")" # works
cat <<< "`dirname "$0"`" # works
cat <<< "$(dirname "$0")" # works
"$(dirname "$0")"/setup_buildroot.sh "$BUILDROOT" # call the sub-script
dirname "$0" # works
echo "`dirname "$0"`" # empty string
echo "$(dirname "$0")" # empty string
cat <<< "`dirname "$0"`" # crash
cat <<< "$(dirname "$0")" # crash
or i do:
dirname "$0" # works
echo "`dirname "$0"`" # works
echo "$(dirname "$0")" # works
cat <<< "`dirname "$0"`" # works
cat <<< "$(dirname "$0")" # works
"`dirname "$0"`"/setup_buildroot.sh "$BUILDROOT" # call the sub-script
dirname "$0" # works
echo "`dirname "$0"`" # empty string
echo "$(dirname "$0")" # empty string
cat <<< "`dirname "$0"`" # crash
cat <<< "$(dirname "$0")" # crash
dirname seems to work fine, but backtick and $() stop working. The command substitution just returns an empty string.
EDIT: removing all the double quotes "" doesn’t have an effect
EDIT2: executing bash explicitly when calling the sub-script has no effect
EDIT3: saving "$(dirname "$0")" to a variable and using that has no effect
EDIT4: adding the same echo commands to the sub-script show that everything is fine in the sub-script
EDIT5: as per request, output of script
/home/jayen/rep
/home/jayen/rep
/home/jayen/rep
/home/jayen/rep
/home/jayen/rep
#setup_buildroot.sh output here
/home/jayen/rep
bash: syntax error near unexpected token `newline'
bash: syntax error near unexpected token `newline'
it doesn’t make sense, but try sourcing your sub-script