Facing a strange problem with the string and also an issue related to trailing space.
Expected output:
I need to use the same logic which was written in the above code. Could you please let me know the way how to get expected output from the above code.
With the evil eval (see many earlier threads) you must consider who can write to the file in question. You are trusting the content to be suitably executable. Syntax errors can cause very confusing results.
What are you trying to achieve here? I've not deciphered it all, but it seems at first glance to be setting variables for your environment within the script before you do any real processing, could you just source the file like this:-
Note that there is no space on the first line between #! and /bin/sh
Of course, you have to ensure that the file is syntactically correct, and it will not allow a mid statement comment. I've added in the echo with the variable name suggested by vbe. It uses escaped double quotes so that they appear in the output. If you don't escape them, the shell assumes that they are to be processed as start/end of string, so that can make your message a bit confusing. Showing the quotes also shows the boundary of your variable, just in case you want it to include a space at the end.
With the evil eval (see many earlier threads) you must consider who can write to the file in question. You are trusting the content to be suitably executable. Syntax errors can cause very confusing results.
What are you trying to achieve here? I've not deciphered it all, but it seems at first glance to be setting variables for your environment within the script before you do any real processing, could you just source the file like this:-
Note that there is no space on the first line between #! and /bin/sh
Of course, you have to ensure that the file is syntactically correct, and it will not allow a mid statement comment. I've added in the echo with the variable name suggested by vbe. It uses escaped double quotes so that they appear in the output. If you don't escape them, the shell assumes that they are to be processed as start/end of string, so that can make your message a bit confusing. Showing the quotes also shows the boundary of your variable, just in case you want it to include a space at the end.
Does that help?
Robin
Liverpool/Blackburn
UK
Thanks for quick response and for the information provided.
As per my requirements, my file should contains a variable with the name as "r.etc". Is there any hack for this which I can use it in my code.
one more thing the output which I am getting at present(with eval command) contains a trailing space. it has to be removed from there it self where I am executing eval command.
The use of a dot in the variable name is a problem, as mentioned by vbe. You might be able to pop in some escape to use it if you really want to, but I've never bothered. Can you really not replace the . with _?
I'm still confused as to what you are attempting. How much control do you have over the input file?
If this is the fixed format, could you not just:-
I know you might want to follow someone else's style, but it would be better for you know understand the logic and code if you are asked to support it. Keep the goal in mind and keep it simple.
Thanks for quick response and for the information provided.
As per my requirements, my file should contains a variable with the name as "r.etc". Is there any hack for this which I can use it in my code.
... ... ...
Need some hacks.
Need a hack. Fine, it is simple. Write your own shell! Standard shells are required to accept user-defined variable names that contain the 52 uppercase and lowercase letters (a-z, A-Z), the 10 digits (0-9) and underscore (_). The shell is allowed to accept other characters in user-defined names, but is not required to do so. I have not seen any standards conforming shell that accepts a period (.) in a user-defined variable name.
I have not seen any standards conforming shell that accepts a period (.) in a user-defined variable name.
I agree, but, in the spirit of "need some hacks!", with ksh93's compound variables you can somewhat fake it. The dot is a delimiter, not actually a character in an identifier name, and compound variables use a more complicated assignment syntax.
I am getting some values from a file and putting them in an array..but the null strings are not getting passed to the array. So during printing the elements ,the null string is not showing in the output. during array size calculation it is also excluding null.Please let me know how to do it.
# cat... (2 Replies)
I have a string like below
Note: I have have a single to any number of comma "," seperated string assigned to jdbc_trgt variable.
I need to split jdbc_trgt using comma(,) as the delimiter.
I tried the below but it fails as i dont know how can i read each split string iterately.
for... (4 Replies)
I'm trying to create a script.
There are 2 files - fileA.log & fileB.log
fileA.log has the below data :
aaaa
cccc
eeee
fileB.log has the below data :
cjahdskjah aaaa xyz
jhaskjdhas bbbb abc
ajdhjkh cccc abc
cjahdskjah ... (7 Replies)
I am storing some unicode characters "лфи" in a char array.
When I view(x/30s <variable name>) the values in gdb it show me something like:
0x80ac47c: "?\004>\004 "
0x80ac482: "A\0048\004;\004L\004D\004>\004=\004:\0045\004/"
Why it is happening so and what are these \004 representing? (1 Reply)
Hi guys,
I need for the bash code below a little bit help: cat script.sh
#!/bin/bash
5_MYVALUE="test"
echo "$5_MYVALUE"
If I try to run the script, got follow failure:
./script.sh
./script.sh: line 4: 5_MYVALUE=test: command not found
_MYVALUE
My questions are how... (4 Replies)
Hi,
i ran following bdf command and found below out with space uses.
prd@prd02/usr/apps/cti>bdf | grep /usr/apps
/dev/vg01/lvol6 17379328 9873783 7036696 58% /usr/apps
/dev/vg01/SYBASE 1228800 978631 234597 81% /usr/apps/sybase
2150400 1108516 976776 ... (3 Replies)
Hi,
I was trying to do a string comparison using if. However, the comparison result is getting treated as a executable statement. I'm not sure where I'm making the mistake!
$ typeset TEST_VAR='YUP'
$ if ; then echo 'Got It!'; fi;
ksh: : not found.
Any help is appreciated! (3 Replies)
Hi all,
I'm not sure but I guess, that is a bash version issue.
The script working fine on "GNU bash, version 3.2.25(1)-release Ubuntu".
#!/bin/bash
while IFS=">" read a id val
do
if ]
then
VAL=${id%<*}; ID=${id#*</}
echo $VAL
echo $ID
sed... (5 Replies)
I have myMethod that gives me available,used,free disk space in KB. I parse the used disk space using awk. That gives me something like 830,016. I want the output to be 830016 so that I can add 100000 to it. In other words I would like to use used_space variable in numeric calculations (using... (5 Replies)
Hello All,
I'm tryying to concatenate string and variables value in ksh, but i'm unable to do it, can someone please help in rectifying my error,
here is the code i have written,
#!/usr/bin/ksh -x
cat $1 | while read fileline
do
val1= echo $fileline | awk -F, '{print $1}'
val2= echo... (3 Replies)