The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 08-26-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 713
Hi.
Quote:
name
A word consisting solely of letters, numbers, and underscores, and beginning with a letter or underscore. Names are used as shell variable and function names. Also referred to as an identifier.

-- excerpt from Bash Reference Manual
Note that the $ is not listed.

There is a way that the look of your requirement can be done -- essentially as an indirect assignment:

Code:
#!/bin/bash -

# @(#) z1       Demonstrate indirect assignment.

echo
a=0
b=1
a=b
echo " first assignment a = $a, b = $b"

echo
$a=2
echo " second assignment a = $a, b = $b"

echo
eval $a=2
echo " eval assignment a = $a, b = $b"

exit

Producing:

Code:
% ./z1

 first assignment a = b, b = 1

./z1: line 12: b=2: command not found
 second assignment a = b, b = 1

 eval assignment a = b, b = 2

However, in general, $ is used as the dereferencing operator in shells. In elementary perl, it must be used to identify scalar variables ... cheers, drl