Find the answer to your Linux question:
Results 1 to 8 of 8
Hi All, what you will write in a shell script to get rows from "emp" table. For ex: getsqldata.sh -- #!/bin/bash ... ... sqlplus .... << HEREDOC select * from ...
  1. #1
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Question simple echo not working in subshell (clearcase)

    Hi All,

    what you will write in a shell script to get rows from "emp" table.

    For ex: getsqldata.sh
    --
    #!/bin/bash

    ...
    ...
    sqlplus .... << HEREDOC
    select * from emp;
    ...
    # more SQL commands....if any
    .....
    HEREDOC
    ..
    .....
    ........
    # Script ends...

    I think the above command will work. when shell scripts encounters sqlplus ....(username/password with appropriate options)...it will execute a subshell and from now onwards till scripts reachs the here document keyword "HEREDOC" as shown above, system will treat each line as a SQL command.

    The problem comming here is that: when at $ prompt I enter "cleartool setview jhola-view_user1" it takes me inside a clearcase view called as: "jhola-view_user1" created by user1....a usual nomenclature.

    and NOW when inside this view, I can run any clearcase related command to get history/ description about a clearcase file/element...etc...other clearcase commands. That's fine. Means When I entered "cleartool setview jhola-view_user1" command at $ prompt (on my 1st shell/session) system created a subshell. Here I can run any Linux command or Clearcase command. Simple Linux commands like at $ prompt (when Im inside the view) like:

    [jhola-view_user1] $ a=10 ; echo $a
    10

    As you see above that inside my view, when I manually assigned a=10, echo printed its value fine.

    BUT, THE BIGGEST issue is coming ....when I want to write a script like below:

    getclearcaseviewdata.sh
    -----------------------
    #!/bin/bash

    a=10
    echo $a----AKS---printing here
    ...
    ....
    cleartool setview jhola-view_user1 << HEREDOC
    ...
    ....
    # clearcase commands
    ..
    ...
    a=100
    echo $a-----SKA----not printing here
    ...
    ...
    # more clearcase commands.....
    .....

    HEREDOC
    ....
    .....
    ...
    ......
    # Script ends...



    Kindly let me know, why system printed variable a's value =10 when I manually set that view at command prompt (inside clearcase view, a subshell)....But system didn't prints a's value = 100 as shown in the script above when I'm setting the view in a script and want to print a's value inside here document body.


    Any helps will be really appreciated. Pls let me know, if you want more info....but I think, I have explained it more that enough.

    Brgds,
    /Arun Sangal
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  2. #2
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Question

    Any helps will be highly remembered!!!
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  3. #3
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Sorry it's not completely clear to me, but for what I can understand, you can try the export command:

    Code:
    export a=10
    Regards

  4. #4
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Question

    Hi Franklin52,

    I'm aware of using export command (used to pass variables to child shells).

    If I have declared and initialized a variable at either $ prompt (before calling the script or within the script, I'm able to print its value inside the `here document` block. But when I'm assigning a value to a variable inside the block itself, it is not printing that value. (See code at last).

    I'm able to print a variable declared at parent shell or within the script, inside the here document ( << ...) block. But when I assigns any variable in the sub-shell itself (created by the command where we have used `here` document funda...system is not printing the value of a variable.

    I'm attaching a codebase snippet, that will clear all doubts. Thanks for helping ....but can you find why system is not printing variable a's value =10.

    Code:
    =========================================
    [/a/b/c/aksutil] $ cat ./g
    #!/bin/bash
    a=100
    cleartool setview testkt2_qabuild << EOC
    cd /vob/code
    a=10
    find . -name fmBuild.pl
    read;
    find . -name fmBuild.pl > ~/aksutil/gg
    cat -n ~/aksutil/gg
    cleartool shell echo '"$a"'
    echo "$a--"
    read
    EOC

    [/a/b/c/aksutil] $ ./g
    ./Fare/server/fmBuild.pl
    1 ./Fare/server/fmBuild.pl
    100
    100--

    [/a/b/c/aksutil] $

    I will check later....as I'm done for the day, I know you | Drl will surely help me in this.

    (!!!Note: One strange thing, if you run the commands in this scripting at $ prompt 1 by 1, system will print a=10).

    Thanks-
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  5. #5
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Try to declare a as a local variable within the here document:

    Code:
    local a=10
    Edit:
    I don't think it should work, the commands you're given within the here document is interpreted by the program that you invoke (cleartool).
    Within the here document, the variable a is an intern variable and it has nothing to do with the "environtment" variable a of the script.

    Regards

  6. #6
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi, Sangal-Arun.
    Quote Originally Posted by Sangal-Arun
    I will check later....as I'm done for the day, I know you | Drl will surely help me in this.
    I don't know how clearcase may affect this, but the shell will have already done parameter expansion in the EOC-EOC here document. Here's an example of how to protect it, although you may need to adapt it for your purposes. This creates a little procedure on file t1, and executes it, once without protection, once with:
    Code:
    #!/bin/sh
    
    # @(#) s1       Demonstrate here document protection.
    
    echo " sh version: $BASH_VERSION"
    
    echo " Unprotected:"
    rm -f t1
    a=100
    cat > t1 <<EOF
    a=10
    echo " My value of a is :$a:"
    EOF
    nl t1
    sh t1
    
    echo
    echo " Protected:"
    rm -f t1
    a=200
    cat >t1 <<'EOF'
    a=20
    echo " My value of a is :$a:"
    EOF
    nl t1
    sh t1
    
    exit 0
    Producing:
    Code:
    &#37; ./s1
     sh version: 2.05b.0(1)-release
     Unprotected:
         1  a=10
         2  echo " My value of a is :100:"
     My value of a is :100:
    
     Protected:
         1  a=20
         2  echo " My value of a is :$a:"
     My value of a is :20:
    The key to this is to surround the opening string EOF with the quotes, see man bash for details on here documents. Best wishes ... cheers, drl

    PS. Please remember to put your scripts, etc., inside CODE tags for easy reading.
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  7. #7
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Excellent explanation drl!

    Regards

  8. #8
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Thumbs up

    Thanks for saving my life.


    Arun
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...