- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Variables, using $ and ${ }_"other words"
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
Forums
Discussions
Discussions
Discussions
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
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
06-12-2006 06:57 AM
06-12-2006 06:57 AM
I have a value kept in $file_galaxy variable but i need to use same variable with date format as follows: $file_galaxy_`date +"%Y%m%d"
but it does not work !!!!
i have tested:
$file_galaxy_`date +"%Y%m%d"
$(file_galaxy)_`date +"%Y%m%d"
${file_galaxy}_`date +"%Y%m%d"
`file_galaxy`_`date +"%Y%m%d"
and any of above shown work !!!!
please help 1!!
I'm using sh and ksh ...
I only obtain: _20060612 or 20060612
thanks ....
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2006 07:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2006 07:05 AM
06-12-2006 07:05 AM
Re: Variables, using $ and ${ }_"other words"
${file_galaxy}_`date +"%Y%m%d`
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2006 07:08 AM
06-12-2006 07:08 AM
Re: Variables, using $ and ${ }_"other words"
sorry i forget to put "`" at the end of the variables:
$file_galaxy_`date +"%Y%m%d"`
$(file_galaxy)_`date +"%Y%m%d"`
${file_galaxy}_`date +"%Y%m%d"`
`file_galaxy`_`date +"%Y%m%d"`
but any way they do not work ..!!!! :'(
help !!!
SOS !!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2006 07:09 AM
06-12-2006 07:09 AM
Re: Variables, using $ and ${ }_"other words"
# echo ${file_galaxy}_`date +"%Y%m%d"`
or
# echo ${file_galaxy}_$(date +"%Y%m%d")
in each of your cases, you are missing the variable-delimiting braces, ${file_galaxy}, and the terminating single-tick for command substitution i.e. `date +"%Y%m%d"`
~cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2006 07:11 AM
06-12-2006 07:11 AM
Re: Variables, using $ and ${ }_"other words"
I wrote:
#!/usr/bin/sh
file_galaxy="testfile"
print $file_galaxy
date=`date +"%Y%m%d"`
print $date
print ${file_galaxy}_`date +"%Y%m%d"`
and got:
./junk.sh
testfile
20060612
testfile_20060612
when run.
I used 11.11 for the test.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2006 07:13 AM
06-12-2006 07:13 AM
Re: Variables, using $ and ${ }_"other words"
All of your examples are missing the final
backtick (`). Also,
Example 1 doesn't work because the shell
thinks the second "_" is part of the
variable name.
Example 2 doesn't work because $(...) runs
the ... as a command.
Example 4 doesn't work because `...` runs
the ... as a command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2006 07:13 AM
06-12-2006 07:13 AM
Re: Variables, using $ and ${ }_"other words"
NEWVAR=${file_galaxy}_$(date '+%Y%m%d')
echo "NEWVAR = \"${NEWVAR}\""
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2006 07:20 AM
06-12-2006 07:20 AM
Re: Variables, using $ and ${ }_"other words"
These are ambiguous variable names. Is the underscore part of the name or is it just another part of the overall interpreted string?
Consider the first one: $file_galaxy_`date +"%Y%m%d"
If I add the closing backtick:
# echo $file_galaxy_`date +"%Y%m%d"`
sh: file_galaxy_: Parameter not set.
Thus, the shell "thinks" that the variable to be interpreted is named "file_galaxy_". Is that what you meant, or did you mean "file_galaxy"?
# echo ${file_galaxy}_`date +"%Y%m%d"`
sh: file_galaxy: Parameter not set.
NOTE that the second time I enclosed the variable name in braces -- {}
This informs the shell of the exact variable name without ambiguity.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2006 07:23 AM
06-12-2006 07:23 AM
Re: Variables, using $ and ${ }_"other words"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2006 07:26 AM
06-12-2006 07:26 AM
Re: Variables, using $ and ${ }_"other words"
It worked with this one:
${file_galaxy}_$(date +"%Y%m%d")
i do not know why this do not work with "`" at the beggining and the end of the variable ..
ANY WAY THANKS TO ALL FRIENDS °!!!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2006 10:35 AM
06-12-2006 10:35 AM
Re: Variables, using $ and ${ }_"other words"
1. The back tick ` looks too much like a forward tick ' (apostrophe)
2. Back ticks can easily be missed in printed text, especially on a fax.
3. Back ticks cannot be nested.
The preferred coding is to use $(commands). Thde $() construct can easily be nested, something like this:
# lvdisplay $(bdf /tmp|tail -1| cut -f1 -d\ )|grep "^LV"
LV Name /dev/vg00/lvol4
LV Permission read/write
LV Status available/syncd
LV Size (Mbytes) 80
This command finds the mountpoint source for /tmp using bdf, then extracts it with cut, uses the value as an argument to lvdisplay and grep grabs all the LV lines. Not possible with backticks.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2006 10:42 AM
06-12-2006 10:42 AM
Re: Variables, using $ and ${ }_"other words"
echo $(lvdisplay $(bdf /tmp|tail -1| cut -f1 -d\ )|grep "^LV Size")|awk '{print $NF}'
which shows the Mbyte size for /tmp. The LV Size line contains the Mbytes number at the end. (somewhat impractical example but shows how $(...$(...)) can be nested.
Bill Hassell, sysadmin