Please see this


Contents

- INDEX
- HP-UX Index
- Solaris
- Linux Index
- Other Unix types
- General Unix
- Unix Networking
- Unix Scripts
- Unix databases

Associated Information

- none

Useful Links

- GAWK Manual
- Sed resources

Using the shell eval command

In shell scripts in is common to set variables using the output of a command, e.g.

variable=`command`

The output from the command is normally a single value. If, however, the command returns multiple values you need to use some other program (e.g. awk or sed) to split the combined result into separate parts. Alternatively, you could pass an argument to the command to specify which result should be returned.

A neater solution is to use the shell's eval command. For example, say you wanted to return day, month and year from the date command. You'd have to write either:

day=`date +%d` month=`date +%m` year=`date +%Y`

or:

result=`date '+%d %m %Y'`

and then break up $result with awk or cut for example. Instead you can write:

eval `date '+day=%d month=%m year=%Y'`

This will set $day, $month and $year as separate variables that can then be used later in the script.


Copyright 2000 Intronet Computers Ltd
Email: Intronet Computers for enquiries