Re: Quick Shell script question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>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@xxxxxxxxxx                                /~\ The ASCII
                                                         \ / Ribbon Campaign
[So it's true, scythe matters.  Willow  5/12/03]          X  Against
Visit - URL: http://vidiot.com/                          / \ HTML Email


-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux