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 !!!
system
December 14, 2010, 1:25am
2
$ 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.
system
December 14, 2010, 1:35am
4
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.
system
December 14, 2010, 1:52am
6
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.
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.
system
December 14, 2010, 2:12am
10
$ 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.
No it doesn't work here.
$ set var="a[5]"
$ echo $var
echo: No match.
Thanks.
system
December 14, 2010, 2:39am
14
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.
ctsgnb
December 14, 2010, 11:30am
16
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`