- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Problems "echoing" variables values
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 02:45 AM
тАО05-02-2006 02:45 AM
Problems "echoing" variables values
When I attribute a value to a variable like this:
TEST1="35"
TEST1="d"
and do this: echo TEST1$TEST2
The result is: 35d
When I grep this values from a text file and attribute it to the same variables, this way:
TEST1=`grep NUM_RELEASE versao.h |cut -f5`
***It puts the value "35" inside the variable TEST1
But when I do again: echo TEST1$TEST2, the result is: d5
Why???
How can I do it in a way that the output is the same for both forms???
Thanks in advance,
Rafael M. Braga
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 02:49 AM
тАО05-02-2006 02:49 AM
Re: Problems "echoing" variables values
TEST1="35"
TEST1="d"
echo TEST1$TEST2
Result should be TEST1
Note that your code echos the characters TEST1 fillowed by a variable that is not set $TEST2
If your screen results are 35d then there is code that has been run or this value is already in the environment variable.
This post is missing information or perhaps contains a typeo.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 02:52 AM
тАО05-02-2006 02:52 AM
Re: Problems "echoing" variables values
The right is $TEST1$TEST2
Thanks again!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 02:52 AM
тАО05-02-2006 02:52 AM
Re: Problems "echoing" variables values
since your commands had some typographical mistakes (like repeating TEST1= assignment twice and missing $ sign on the echo commands) I am not quite sure where your problem lies. If you can include the output of
grep NUM_RELEASE versao.h
and the exact command/commands that you are trying to run, here in your post, you can get a better answer in my opinion
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 02:53 AM
тАО05-02-2006 02:53 AM
Re: Problems "echoing" variables values
first I assume the second assign of TEST1 should be TEST2.
TEST1="35"
TEST2="d"
echo ${TEST1}${TEST2}
should give you: 35d
Also what shell : echo $0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 02:53 AM
тАО05-02-2006 02:53 AM
Re: Problems "echoing" variables values
It must be getting control characters from versao.h, so try this:
grep NUM_RELEASE versao.h |cut -f5 | od -bc
and post the output here.
live free or die
harry d brown jr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 03:55 AM
тАО05-02-2006 03:55 AM
Re: Problems "echoing" variables values
$ grep NUM_RELEASE versao.h |cut -f5 | od -bc
0000000 063 065 015 012
3 5 \r \n
0000004
And the simple output:
$ grep NUM_RELEASE versao.h
#define NUM_RELEASE 35
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 06:15 AM
тАО05-02-2006 06:15 AM
Re: Problems "echoing" variables values
As others suggested, you are being pestered by control characters.
What is going to your screen is: 3, 5, Carriage-Return ( = \r = 015 ), d
The VISUAL effect of this is d5.
On an oldfashioned hardcopy terminal you would see the overpunch, but screens just give the last character in a given position.
Your input file probably came from a WINDOZE box and has CR-LF as line terminators, not the LF Unix expects.
Just push your file through DOS2UX and all will be well.
Note... the Cut -f5 works because you apparently have TABs in the input. To forum does not display that. It may be more save to parse for 'whitespace', or just pick up the last field for example with awk:
awk '{print $NF}' x
Of course awk (or perl) will also happily remove the CR for you:
awk '{x=$NF; sub(/\r/,"",x); print x }' x | od -bc
0000000 063 065 012
3 5 \n
Hth,
Hein.
$ perl -e 'print "#define NUM_RELEASE 35\r\n"' > x
$ grep NUM x | cut -d' ' -f3 | od -bc
0000000 063 065 015 012
3 5 \r \n
0000004
$ y=d
$ x=`grep NUM_RELEASE x |cut -d' ' -f3`
$ echo $x$y
d5
$ echo $x$y > xx
bash-2.04$ od -bc xx
0000000 063 065 015 144 012
3 5 \r d \n
0000005
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 09:00 AM
тАО05-02-2006 09:00 AM
Re: Problems "echoing" variables values
If that still is a problem, do the grep to TEST1 as above, then do this:
TEST3=`print -r $TEST1`
which should give you just the "35" in TEST3 without any control characters.
mark