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 ...
- 05-07-2007 #1
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
- 05-12-2007 #2
Any helps will be highly remembered!!!
- 05-12-2007 #3Linux 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:
RegardsCode:export a=10
- 05-12-2007 #4
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-
- 05-12-2007 #5Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try to declare a as a local variable within the here document:
Edit:Code:local a=10
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
- 05-12-2007 #6Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi, Sangal-Arun.
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:
Originally Posted by Sangal-Arun
Producing: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
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, drlCode:% ./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:
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 )
- 05-13-2007 #7Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Excellent explanation drl!
Regards
- 05-16-2007 #8
Thanks for saving my life.
Arun


