While loop subshell problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While loop subshell problem
# 1  
Old 10-15-2011
Question While loop subshell problem

Hi,

I have the below script

Code:
while true; do
       read -p "Please enter schema password: " -s -e pswd1
       echo
       read -p "Please retype schema password: " -s -e pswd2
       echo
       [ "X$pswd1" != "X$pswd2" ] && { echo -e "password mismatch.\n"; continue; }
       validateOraclePassword $pswd1
       [ $? -eq 0 ] && break
done

where "validateOraclePassword" is a function which checks if the password follow our database policy.

The above code is used by multiple components and so i'm trying to build a master script which calls all components in 1 go as below

Code:
/opt/component1.sh <<!
password
password
!
/opt/component2.sh <<!
password1
password1
!

My problem is that WHILE loop creates a subshell when it run and because of that the $pswd1 is empty when validateOraclePassword function is called.


Any idea how i can fix it?

Many thanks in advanced,

Dani
# 2  
Old 10-15-2011
Code:
while true; do
       read -p "Please enter schema password: " -s -e pswd1
       echo
       read -p "Please retype schema password: " -s -e pswd2
       echo
       if [ "X$pswd1" != "X$pswd2" ] || [ "X$pswd1" == "X" ]; then
           echo -e "password mismatch or password is empty.\n"; continue;
       else
          echo validateOraclePassword $pswd1
          [ $? -eq 0 ] && break
      fi
done

# 3  
Old 10-15-2011
MySQL

Quote:
Originally Posted by rdcwayx
Code:
while true; do
       read -p "Please enter schema password: " -s -e pswd1
       echo
       read -p "Please retype schema password: " -s -e pswd2
       echo
      if [ "X$pswd1" != "X$pswd2" ] || [ "X$pswd1" == "X" ]; then
          echo -e "password mismatch or password is empty.\n"; continue;
      else
echo validateOraclePassword $pswd1 > /dev/null
         [ $? -eq 0 ] && break
     fi
done

It does work with a minor change as i don't want to show the password in clear Smilie

Many thanks,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Infinite "while" loop subshell loses current date variable

I have a simple script to log network connectivity to a set of systems. However, as expected the date appended to the log never changes because the new variable is lost when the loop starts again. Can someone clue me in on how to get around this issue? #!/bin/bash LOG=/tmp/netlog... (3 Replies)
Discussion started by: woodson2
3 Replies

2. Shell Programming and Scripting

Help sending mail through subshell

Hey I have a shell script that is like this: ( echo "hi!" ##DO SOMETHING )&( sleep 5 ##EMAIL RECIPIENTS VARs ERECIPIENT3="email.com" echo "Connection on status: is Down"|mail -s "Subject:" ${ERECIPIENT3} kill -- -$$ ) This isn't working anyone know why? mail won't go out from... (12 Replies)
Discussion started by: mo_VERTICASQL
12 Replies

3. Shell Programming and Scripting

Executing a command in subshell

Hi All, I am trying to create a shell script which runs on my linux machine. The requirement is so that, ade createview xyz -> this steps creates a view ade useview xyz -> we are entering inside the view ade begintrans -> begin a transaction My script has following code : lets say... (2 Replies)
Discussion started by: Dish
2 Replies

4. Shell Programming and Scripting

While loop subshell problem

People, Here is my code while read ln do xyz=$(echo $ln/$val1*100-100|bc -l|xargs printf "%1.0f\n") if && ; then iam="YELLOW" fi done <<< "$(grep "^" $TMPOUT)" where $TMPOUT is a flat file which contains a set of values. Whilst executing the above, I get an error... (4 Replies)
Discussion started by: sathyaonnuix
4 Replies

5. Shell Programming and Scripting

Basename in subshell

Hi All, I would like to improve my bash scripting skill and found a problem which I do not understand. Task is to search and print files in directory (and subdirecories) which contains its own name. Files can have spaces in name. This one works fine for files in main directory, but not for... (4 Replies)
Discussion started by: new_item
4 Replies

6. Shell Programming and Scripting

redirect stdout and stderr to file wrong order problem with subshell

Hello I read a lot of post related to this topic, but nothing helped me. :mad: I'm running a ksh script with subshell what processing some ldap command. I need to check output for possible errors. #!/bin/ksh ... readinput < $QCHAT_INPUT |& while read -p line do echo $line ... (3 Replies)
Discussion started by: Osim
3 Replies

7. Shell Programming and Scripting

getopts in a subshell

Hello, I've a little problem with one of my ksh scripts and I manage to narrow it to the script here: #!/bin/ksh writeLog() { paramHandle="unknown" OPTIND=1 while getopts :i: option $* do case $option in i) paramHandle=${OPTARG} ;; esac done echo... (2 Replies)
Discussion started by: Dahu
2 Replies

8. Shell Programming and Scripting

Killing a subshell

I am calling a script from with another script and reading its output one line at a time (using <childscript> | while read line) in the parent script. If the output exceeds a predefined number of lines I want to kill the child shell from within the parent shell. I decided to print the process ID... (2 Replies)
Discussion started by: slash_blog
2 Replies

9. Shell Programming and Scripting

Passing arguments to the subshell

I have a shell script which is invoked by passing an argument. The outer shell script calls another subshell and I want the argument passed down to flow down to the subshell. E.g Invoking a shell ======>> abc_refresh.ksh NM Below is the content of abc_refresh.ksh Value1=$1... (7 Replies)
Discussion started by: Mihirjani
7 Replies

10. Shell Programming and Scripting

Subshell Question

The profile of the user is empty. Then before I run the script I want I run a parameter file that populates the variables for oracle. ORACLE_HOME ORACLE_BASE ORACLE_SID PATH etc ... But it seems that these variables are not making it to the shell I am in because when I do an echo on... (6 Replies)
Discussion started by: lesstjm
6 Replies
Login or Register to Ask a Question