Проблема Bash -x и sed
Я скопировал следующее из LibreOffice и использовал функцию "best guess", чтобы опубликовать его. Надеюсь, форматирование пройдет.
I am using the following function to output current line of bash -x debug script. echo_line_no () { grep -n "$1" $0 | sed "s/echo_line_no//" # grep the line(s) containing input $1 with line numbers #replace the function name with nothing } I did not write the function and unfortunately do not recall the source. The function works when “S1” contains plan text, such as echo_line_no "START NEW_BuildCommand" The function does not work as expected when “$1” contains “variables “ consequently bash -x debug option outputs only first pass to the function when used in sequence. Bash script choice="$USERINPUT" 4611 DynamicCommand="$choice" 4612 4613 echo_line_no "Current DynamicCommand" 4614 pause 4615 echo_line_no "Current DynamicCommand $DynamicCommand" 4616 echo_line_no "Current DynamicCommand "$DynamicCommand" " 4617 4618 pause 4619 echo_line_no "END NEW_BuildCommand" 4620 pause Output from bash -x + choice=lsusb + DynamicCommand=lsusb outputs shows pass thru echo_line_no function as expected + echo_line_no 'Current DynamicCommand' + sed s/echo_line_no// + grep -n 'Current DynamicCommand' /usr/bin/raspi-config-DEBUG.sh outputs text and line number as expected 4613: "Current DynamicCommand" fails to output pass thru echo_line_no function and does not output variable 4615: "Current DynamicCommand $DynamicCommand" 4616: "Current DynamicCommand "$DynamicCommand" " + pause
Что я уже пробовал:
Я не понимаю, почему эта функция терпит неудачу, поэтому я не угадал обходной путь / решение.
Но я попробовал другой синтаксис для переменной.