- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Difference between $( <command> ) and `<comman...
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
тАО03-11-2005 01:54 AM
тАО03-11-2005 01:54 AM
Since a POSIX course at HP I learned to write proper POSIX, so I always use $(
But today I tried to fill a variable with an SQL*PLUS query and came up with an issue.
With the following example I will try to explain the problem:
$export SQLDBA='sqlplus -s'
$echo $( ${SQLDBA} <<-EOF
/ as sysdba
set head off
select value from v\\$nls_parameters where parameter = 'NLS_CHARACTERSET';
exit;
EOF )
sh: nls_parameters: Parameter not set.
echo ` ${SQLDBA} <<-EOF
/ as sysdba
set head off
select value from v\\$nls_parameters where parameter = 'NLS_CHARACTERSET';
exit;
EOF `
AL32UTF8
I thought it wouldn't matter which method to use. Did I just find a crop circle?
I prefer to use the $( ) method, so can anyone explain this behaviour and tell me how to use $( )? In fact I want to fill a variable, so in my script the тАЬechoтАЭ will be replaced by тАЬVAR=тАЭ
Thanks in ad
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2005 03:02 AM
тАО03-11-2005 03:02 AM
Re: Difference between $( <command> ) and `<command>`
$export --> export
$echo ---> echo
heredocs <<-EOF but terminated by EOF
An extra backslash before $
This should be much closer to functional code:
export SQLDBA='sqlplus -s'
echo $( ${SQLDBA} <<-EOF
/ as sysdba
set head off;
select value from v\$nls_parameters where parameter = 'NLS_CHARACTERSET';
exit;
-EOF
)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2005 03:27 AM
тАО03-11-2005 03:27 AM
Solutionif <<- is used, leading tabs are ignored
as it looks like they are running this from the command line it would be interesting to know if the results are the same from a file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2005 03:28 AM
тАО03-11-2005 03:28 AM
Re: Difference between $( <command> ) and `<command>`
I cant find my docs...but your issue is with encapsulated variables (variable of (variable...))
not very posix...
I remembered going through such cases and the way out is using eval...
now an elegant way would be:
alias sq='sqlplus -s'
export SQLDBA='sqlplus -s'
echo $( ${SQLDBA} <<-EOF
/ as sysdba
set head off;
select value from v\$nls_parameters where parameter = 'NLS_CHARACTERSET';
exit;
-EOF
)
All the best
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2005 03:31 AM
тАО03-11-2005 03:31 AM
Re: Difference between $( <command> ) and `<command>`
alias sq='sqlplus -s'
echo $( ${sq} <<-EOF
/ as sysdba
set head off;
select value from v\$nls_parameters where parameter = 'NLS_CHARACTERSET';
exit;
-EOF
)
Was what I wanted...
All the best
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2005 03:52 AM
тАО03-11-2005 03:52 AM
Re: Difference between $( <command> ) and `<command>`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2005 06:09 AM
тАО03-11-2005 06:09 AM
Re: Difference between $( <command> ) and `<command>`
1. `` is much too easily confused with '' so copying a script (by someone unfamiliar with the proper usage of grave accent marks) usually has a lot of errors, and
2. grave accent marks cannot be nested so you can't use the result of one process (command substitution) as a parameter to another process which is itself being used as a command substitution.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2005 09:23 AM
тАО03-11-2005 09:23 AM
Re: Difference between $( <command> ) and `<command>`
Thanks all for the quick responses. I'm sorry for the leading '$'. That was only the prompt copied and pasted. Maybe that wasn't really handy...
The extra minus sign in my heredoc was indeed to ignore leading tabs.
The code is in a function in a script and will be used by another function (which is still in the pen).
If executed from a script (with the braces), an "l" (like ls with IFS=\040) of the current working is given, together with an ORA-902 ERROR.
Like I asked before: Why does the POSIX method act differently (thus incorrect) than the Bourne method while using the identical syntax??
The issue isn't really the heredocs or the aliases, but the fact that using a dollar {$} and quotes {'} make that POSIX doesn't work and Bourne is successful?
The actual code is:
# make this one global, it will be used more often
export SQLDBA='sqlplus -s'
function f_get_charset
{
CHARSET=$(
${SQLDBA} <<-EOF
/ as sysdba
set head off
select value from v\\$nls_parameters where parameter = 'NLS_CHARACTERSET';
exit;
EOF
)
# End of f_get_charset
}
Any suggestions? I really want to use POSIX, because I like (good) standards and don't want to let my scripts getting messy.
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-11-2005 11:27 AM
тАО03-11-2005 11:27 AM
Re: Difference between $( <command> ) and `<command>`
the `` method you need to use v\\$nls_parameters (two backslashes)
why?
from the man page:
Command Substitution
The standard output from a command enclosed in parenthesis preceded by a dollar sign ($(...)) or a pair of grave accents (`...`) can be used as part or all of a word; trailing newlines are removed. In the second (archaic) form, the string between the accents is processed for special quoting characters before the command is executed. See the "Quoting" subsection.
Inside grave accent marks (`...`), \ quotes the characters \, `, and $.
as an example try this
echo "$(cat <<-ABC
from v\$nls_parameters
ABC
)"
echo `cat <<-ABC
from v\\$nls_parameters
ABC
`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2005 08:49 PM
тАО03-14-2005 08:49 PM
Re: Difference between $( <command> ) and `<command>`
I Tried with a "set -x" at the first line of the function (That's debug mode).
When I try your syntax, I found out that the single qoutes are changed into double quotes.
Look in the man-pages in the section "Quoting" for a solution.
Cheers,
Rene