Sponsored Content
Full Discussion: Back ticks and $()
Top Forums Shell Programming and Scripting Back ticks and $() Post 302843194 by bobbygsk on Monday 12th of August 2013 10:27:50 AM
Old 08-12-2013
Back ticks and $()

In one of my previous threads, someone suggested not to use backticks. When I googled, I came to know that back ticks are deprecated instead $() should be used. But I face issue while using $().
Note: I used echo of the sql just to debug.

The following is the code
Code:
#!/bin/ksh
#set -x
ScriptDir=$(dirname $0)
. ${ScriptDir}/setEnv.sh
VAL=X

  echo "\$(sqlplus -s $user_name/$user_pwd@$database_name <<EOF
     set pagesize 0 LINESIZE 1000 feedback off verify off heading off echo off
     select count(1) from dual where dummy = '$VAL';
    EXIT;
  EOF)"

  REC_EXIST=$(sqlplus -s $user_name/$user_pwd@$database_name <<EOF
  set pagesize 0 LINESIZE 1000 feedback off verify off heading off echo off
  select count(1) from dual where dummy = '$VAL';
  EXIT;
  EOF)

  echo "CHECK RUN STATUS"
  run_status=$?
  echo "RUN STATUS    : $run_status"
  echo "REC_EXIST      : $REC_EXIST"

  if [ $REC_EXIST == 0 ] ;then
    echo "No Records    : $REC_EXIST"
  else
    echo "Records exists: $REC_EXIST"
  fi

The above code works fine as long as I use back tick. When I replace backticks with $(), I encounter the following error
Code:
$(sqlplus -s xxxxxxx/xxxxx@xxxxxxx <<EOF
       set pagesize 0 LINESIZE 1000 feedback off verify off heading off echo off
       select count(1) from dual where dummy = 'X';
       EXIT;
       EOF)


CHECK RUN STATUS
RUN STATUS    : 0
REC_EXIST     :   select count(1) from dual where dummy = "$VAL"
                                          *
ERROR at line 1:
ORA-00904: "$VAL": invalid identifier
test.sh[XX]: count(1): unknown test operator
Records exists:   select count(1) from dual where dummy = "$VAL"
                                          *
ERROR at line 1:
ORA-00904: "$VAL": invalid identifier
Records exists:   select count(1) from dual where dummy = "$VAL"
                                          *
ERROR at line 1:
ORA-00904: "$VAL": invalid identifier

By using $() I got good results for other scripts. Can anyone explain what went wrong.
Appreciate your response
 

6 More Discussions You Might Find Interesting

1. HP-UX

Ticks in seconds.

Hello all, Is there any thumb rule or aproximation of the equivalence in second of one tick? Thank you in advance. (1 Reply)
Discussion started by: mig28mx
1 Replies

2. AIX

back to back printing in UNIX

Hi , Can you suggest me how to back to back printing in UNIX? Is there any way? Kindly advise. Regards Vijaya Amirtha Raj (3 Replies)
Discussion started by: amirthraj_12
3 Replies

3. IP Networking

Back-to-Back Connection using HBAs

Hi every body, Is it possible to connect two servers Back-to-Back (Point-to-Point) using HBA adapters & using Fiber. Note it is direct connection & there is no switches between the servers. I'm concern about using HBA adapters, it is possible or not. Thanks in advance. :) (3 Replies)
Discussion started by: aldowsary
3 Replies

4. Shell Programming and Scripting

Shell Script problem $( vs ticks [`]

ok so, I recently started using $(echo one two three) to execute commands in scripts instead of using `echo one two three`. This method works wonderfully on ubuntu. However, it doesn't seem to work on other unix systems, i.e redhat/sun sun solaris. I really hate to go back to the ticks "`"... (2 Replies)
Discussion started by: SkySmart
2 Replies

5. Shell Programming and Scripting

Passing variable to Expression in back ticks.

Hi, In my perl script I want to check whether *.csv files exist and take the count . Below is the code: $path = “/home/usr/jan/myfiles” my $File_Count = `ls *.csv | wc -l `; # Checks in the current directory #Works fine if files exists. my $File_Count = `ls $path/*.csv | wc -l `; # I need... (2 Replies)
Discussion started by: jisha
2 Replies

6. What is on Your Mind?

I'm back

Hi all, I used to post here years ago, and was a moderator, my old username: zazzybob. Anyway, after a few years away focusing on my career, I'm back and keener than ever to get involved in the unix.com community again. I'm looking forward to getting back into the swing of things, helping... (11 Replies)
Discussion started by: tokiwinter
11 Replies
echo(1B)					     SunOS/BSD Compatibility Package Commands						  echo(1B)

NAME
echo - echo arguments to standard output SYNOPSIS
/usr/ucb/echo [-n] [argument] DESCRIPTION
echo writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. echo is useful for producing diagnostics in command files and for sending known data into a pipe, and for displaying the contents of envi- ronment variables. For example, you can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows: o echo your current-working-directory's full pathname o pipe the output through tr to translate the path's embedded slash-characters into space-characters o pipe that output through wc -w for a count of the names in your path. example% /usr/bin/echo "echo $PWD | tr '/' ' ' | wc -w" See tr(1) and wc(1) for their functionality. The shells csh(1), ksh(1), and sh(1), each have an echo built-in command, which, by default, will have precedence, and will be invoked if the user calls echo without a full pathname. /usr/ucb/echo and csh's echo() have an -n option, but do not understand back-slashed escape characters. sh's echo(), ksh's echo(), and /usr/bin/echo, on the other hand, understand the black-slashed escape characters, and ksh's echo() also understands a as the audible bell character; however, these commands do not have an -n option. OPTIONS
-n Do not add the NEWLINE to the output. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), echo(1), ksh(1), sh(1), tr(1), wc(1), attributes(5) NOTES
The -n option is a transition aid for BSD applications, and may not be supported in future releases. SunOS 5.10 3 Aug 1994 echo(1B)
All times are GMT -4. The time now is 01:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy