HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: value assignment problem in script
Operating System - HP-UX
1832069
Members
2824
Online
110034
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
01-01-2004 07:31 PM
01-01-2004 07:31 PM
Hi everybody,
Best wishes for 2004 to all.
I have a small problem with the assignment of a value to a script variable.
When running the following expression in the shell :
echo "Dec 9 09" | awk '{printf "%s %2s %s", $1,$2,$3}'
I get the correct output :
Dec 9 09
Notice that there are 2 spaces between 'Dec' and '9' in the output.
However, running the statement in a script statement like this :
datum=`echo "Dec 9 09" | awk '{printf "%s %2s %s", $1,$2,$3}'`
echo $datum
Then I get this output :
Dec 9 09
Notice there is only 1 space between 'Dec' and '9' now.
Any suggestions ?
Thanks in advance,
Franky
Best wishes for 2004 to all.
I have a small problem with the assignment of a value to a script variable.
When running the following expression in the shell :
echo "Dec 9 09" | awk '{printf "%s %2s %s", $1,$2,$3}'
I get the correct output :
Dec 9 09
Notice that there are 2 spaces between 'Dec' and '9' in the output.
However, running the statement in a script statement like this :
datum=`echo "Dec 9 09" | awk '{printf "%s %2s %s", $1,$2,$3}'`
echo $datum
Then I get this output :
Dec 9 09
Notice there is only 1 space between 'Dec' and '9' now.
Any suggestions ?
Thanks in advance,
Franky
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2004 07:37 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2004 07:43 PM
01-01-2004 07:43 PM
Re: value assignment problem in script
The problem with the ITRC is that multiple spaces are replaced by a single one, so it is not visible to us.
The problem is with the shell and the echo command...
Your variable datum is containing the correct value, but:
echo $datum
will be written out by the shell to
echo Dec 9 09
(with two spaces between Dec and 9)
which means echo will get 3 arguments: 'Dec', '9' and '09'.
Now echo displays the arguments with only 1 space between them. If you changed the 2 to a 3 in your printf statement, the result would have been the same.
To solve your problem, add quotes to the echo statement, to have the contents of $datum being one argument for echo:
echo "$datum"
The problem is with the shell and the echo command...
Your variable datum is containing the correct value, but:
echo $datum
will be written out by the shell to
echo Dec 9 09
(with two spaces between Dec and 9)
which means echo will get 3 arguments: 'Dec', '9' and '09'.
Now echo displays the arguments with only 1 space between them. If you changed the 2 to a 3 in your printf statement, the result would have been the same.
To solve your problem, add quotes to the echo statement, to have the contents of $datum being one argument for echo:
echo "$datum"
Every problem has at least one solution. Only some solutions are harder to find.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2004 07:48 PM
01-01-2004 07:48 PM
Re: value assignment problem in script
Thanks!
That is the solution for me !
Franky
That is the solution for me !
Franky
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP