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.

 $ 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 !!!

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

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.

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

Hi Rohon,

It doesn't work here.

$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.

try:

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

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.

Edited post #6

Here is what I see here,

$ basename `cat bp`
q[3]

$ a="$1"
a=: Command not found.

$ echo $a  

Note : I did try setting set a="$1", as well

Thanks.

$ set a=`cat bp | basename`
$ echo $a

I did try it, still it has an issue ... ( basename doesnt work in this fashion )

$ cat bp | basename
basename: missing operand
Try `basename --help' for more information.

Just FYI ( to keep it even simpler )

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

I believe unix thins [] to be as a range, I do not see a way to escape it either.

Thanks.

$ set var="a[5]"

does it work?

No it doesn't work here.

 $ set var="a[5]"
 $ echo $var
echo: No match.

Thanks.

try:

$ set var="a[5]"
 $ echo "$var"

Hi Rohon,

Thanks for all your prompt replies, I managed to get it working using,

My intent was to get "abd/asd" from "abd/asd/a[5]" and use it in script later.

> set a= `rev bp | cut -d"/" -f2- | rev` 
>echo $a
abd/asd

Appreciate your timely help !!!

Best Regards,
Mani BR.

You are in C shell (csh)
then you should remove the = sign when you set a variable :

 set a `rev bp | cut -d"/" -f2- | rev`