home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 46.2 Quoting Trouble?  Think, Then Use echo Chapter 46
Shell Script Debugging and Gotchas
Next: 46.4 Stop Syntax Errors in Numeric Tests
 

46.3 Bourne Shell Debugger Shows a Shell Variable

If you have a shell script that sets several variables and you want to show the value of one of them, you can add a loop that asks you forvariable names and displays their values : (45.19 )

% cat myscript


#!/bin/sh
   ...
while echo "Pick a variable; just RETURN quits: \c"
      read var
do
      case "$var" in
      "") break ;;
      *)  eval echo \$$var ;;
      esac
done

The loop prompts Pick a variable: , then reads a value; if you type an empty answer, the loop quits. Otherwise, the value of that variable is displayed; the eval (8.10 ) command scans the echo command line twice.

This tip isn't just good for debugging. It's good in any shell script where you need to show the value of a variable by typing its name.

- JP


Previous: 46.2 Quoting Trouble?  Think, Then Use echo UNIX Power Tools Next: 46.4 Stop Syntax Errors in Numeric Tests
46.2 Quoting Trouble? Think, Then Use echo Book Index 46.4 Stop Syntax Errors in Numeric Tests

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System