assign var with set=a[5] not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting assign var with set=a[5] not working
# 1  
Old 12-14-2010
assign var with set=a[5] not working

Hi Experts,

I'm having issue in assigning var with special character [], please see below for complete details.
Code:
 $ echo $SHELL
/bin/csh

$ cat bp
abd/asd/a[5]

$ awk -F "/" '{print $NF}' bp | awk '{print $1}'
a[5]

$  set a=`awk -F "/" '{print $NF}' bp | awk '{print $1}'`

$ echo $a 
echo: No match    <=============

$  set=a[5]
set=a[5]: No match. <============

Thanks for any help !!!

Last edited by Scott; 12-14-2010 at 03:13 AM.. Reason: Please use code tags
# 2  
Old 12-14-2010
Quote:
$ cat bp
abd/asd/a[5]

$ awk -F "/" '{print $NF}' bp | awk '{print $1}'
a[5]
Code:
$ awk -F "/" '{print $NF}' bp              # Why u need awk '{print $1} ??
a[5]

R0H0N
# 3  
Old 12-14-2010
Hi Rohon,

I intend to use the stored variable in my shell script later ( $a )
Code:
set a=`awk -F "/" '{print $NF}' bp | awk '{print $1}'`


Thanks.

Last edited by Scott; 12-14-2010 at 03:13 AM..
# 4  
Old 12-14-2010
Quote:
Originally Posted by novice_man
Hi Rohon,

I intend to use the stored variable in my shell script later ( $a )

set a=`awk -F "/" '{print $NF}' bp | awk '{print $1}'`

Thanks.
Code:
set a=`awk -F"\/" '{print $NF}' bp`
echo $a                          # This will print a[5]

R0H0N
# 5  
Old 12-14-2010
Hi Rohon,

It doesn't work here.
Code:
$cat bp
asd/dad/a[5]

$ set a=`awk -F"\/" '{print $NF}' bp`
awk: warning: escape sequence `\/' treated as plain `/'

$ echo $a
echo: No match.

Thanks.

Last edited by Scott; 12-14-2010 at 03:14 AM..
# 6  
Old 12-14-2010
try:

Code:
$ basename `cat bp`
$ a="$1"
$ echo $a                         # This will print a[5]


Last edited by R0H0N; 12-14-2010 at 03:03 AM..
R0H0N
# 7  
Old 12-14-2010
Hi Rohon,

Yes it get a[5], the problem i have is I'm unable to store into a Unix variable.
Can you please let me know, how can I store the output as a unix variable.

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using read to assign value to bash variable not working

Hi, I am attempting to assign the output of the following command, to two bash variables, var1 and var2 using "read," but it doesn't seem to be working. # openstack hypervisor stats show | awk -F'|' 'NR==14{print $2,$3}' vcpus 92 # echo $? 0 # openstack hypervisor... (4 Replies)
Discussion started by: sand1234
4 Replies

2. Shell Programming and Scripting

Csh , how to set var value into new var, in short string concatenation

i try to find way to make string concatenation in csh ( sorry this is what i have ) so i found out i can't do : set string_buff = "" foreach line("`cat $source_dir/$f`") $string_buff = string_buff $line end how can i do string concatenation? (1 Reply)
Discussion started by: umen
1 Replies

3. Windows & DOS: Issues & Discussions

How to automatically set the DISPLAY var?

Hi all, Our users use Putty on Windows servers to log on to UNIX via SSH and run GUI applications. Is there a way to automatically get the display numbers from xming or Exceed (that are running on Windows) to set the DISPLAY var properly on UNIX? X11 forwarding is not an option. The closest I... (3 Replies)
Discussion started by: ejianu
3 Replies

4. Programming

assign array with a local var???

Hi all, I am just wondering is this (below code) valid in programming int xx = 10110; int i; long yy = {1,2,3,4,5,6,7,8,xx}; I compiled this using gcc will all working option successfully without getting any warning or error. I didn't see this kind of code in my past... (7 Replies)
Discussion started by: zing_foru
7 Replies

5. UNIX for Advanced & Expert Users

assign array with a local var???

topic moved to programming (0 Replies)
Discussion started by: zing_foru
0 Replies

6. Shell Programming and Scripting

how to create variables in loop and assign filename after set command?

Hi, does anybody knows how to manage, that the filenames are assigned to a variable in a loop afer getting them with set command in a ksh, like: set B*.txt i=1 c=$# x=$((c+1)) echo "$x" while ] ; do _ftpfile$i="$"$i echo "$_ftpfile$i" i=$((i+1)) done The first echo returns,... (2 Replies)
Discussion started by: spidermike
2 Replies

7. Shell Programming and Scripting

SSH script. (Assign $var to free cmd) ???

Running: GNU/Linux, 2.6.22.9-61.fc6 (hope that's the right info needed) I am trying give the amount of RAM and the % used. I am using free command. I am having some problems with this command code: 1)T = `free | grep Mem | awk '{print $2}'` F = `free | grep Mem | awk '{print $4}'`... (3 Replies)
Discussion started by: AngelFlesh
3 Replies

8. Shell Programming and Scripting

assign shell var output of cmd "wc"

how do I feed output of "wc" to a shell script variable "countBcp"? (2 Replies)
Discussion started by: devy
2 Replies

9. Shell Programming and Scripting

Difference between "set $<var>" and "set -- $<var>"

Hi pros, Could anyone tell me the actual difference between setting the positional parameters from the variable using the following commands? $ var="This is my question" $ set $var $ echo $1 --> 'This' $ echo $2 --> 'is' .... .... and $ var="This is my question" $ set --... (3 Replies)
Discussion started by: royalibrahim
3 Replies

10. Shell Programming and Scripting

assign value to variable is not working

Hi :) The next script campares two files File1-Line1 vs File2-Line1, File1-Line1 vs File2-Line2... only if line contains "AS-", if LineX is not in File2 writes in aux, but "valor" is allways=1 never changes! :confused: What is wrong? valor changes to 0 before break, after brake is again 1 ... (3 Replies)
Discussion started by: agustincm
3 Replies
Login or Register to Ask a Question