Quick Shell script question

Vidiot brown at mrvideo.vidiot.com
Thu Jun 3 15:54:41 UTC 2004


>I have been trying to do something that seems that it should be very
>simple in a shell script. I am trying to make a variable equal to the
>output of a command. The command started off very complex but I created
>a test script to bring it down to it's most simple form and it still
>does not work. Here is the test script:
>
>#!/bin/bash
># test script
>
>test1='pwd'
>echo $test1
>
>when in this format the test1 variable echo's the word pwd instead of
>the current directory.
>I have also tried
>test1= 'pwd'      # test1 is null and command executes
>I am almost positive I have done this before in a script. 
>Any help would be appreciate.

The correct syntax is:

test1=`pwd`
echo $test1

The ' characters is used to indicate that variable substitution is not to be
done, i.e.,

	test='$variable'

will assign the string $variable to the test variable.  If " is used, then
variable sustitution is done, i.e.:

	variable=35
	test="$variable"

will assign 35 to the test variable.

The ` character is used for command subsitution.

All of this is explained in the sh man page.

MB
-- 
e-mail: vidiot at vidiot.com                                /~\ The ASCII
                                                         \ / Ribbon Campaign
[So it's true, scythe matters.  Willow  5/12/03]          X  Against
Visit - URL: http://vidiot.com/                          / \ HTML Email





More information about the redhat-list mailing list