0

when I use encpass from command line : no problem

#!/bin/sh
label=$1
. ./encpass.sh
password=$(get_secret  $label)
echo "passw $password
[dbadmin@luechdb61 scripts]$ ./secret.sh  dbllud1
passw Vxxxxxxxxxxxxxxxxxxxxxxxx
[dbadmin@luechdb61 scripts]$ ./secret.sh  dbllud2
passw Tyyyyyyyyyyyyyyyyyyyyyyyyy

password is correctly retrieved now I call it from another script ......

    usr_name=$(echo ${server_name} |cut -d ':' -f3)
        echo "handling script_name ${Scr_nme} for server_name : ${srv_name=} dbname : ${db_name} "
        . ./encpass.sh
        password=$(get_secret ${usr_name})
...

in this case : I also echoed the input and is correct but get_secret does not recognize this and wants to create a new entry although the entry is correctly displayed

[dbadmin@luechdb61 scripts]$ ./db2Deploy.sh -s scr.sql -m deploy.lst -e d
handling script_name scr.sql for server_name : luechdb61 dbname : IEEINT
xdbllud1x   <--- echo from script x${usr_name}x
Enter dbllud1:
stty: standard input: Inappropriate ioctl for device
stty: standard input: Inappropriate ioctl for device

what could be the reason for this ? thanks for all answer best regards, Guy

1
  • Suggestion for the future: provide always a complete working (simplified) code, not only spare snippets. How to create a Minimal, Reproducible Example Commented May 12, 2020 at 13:33

1 Answer 1

1

When you execute a command, the standard input stream of that command is taken from the keyboard and the standard output and error stream go to the screen of the terminal.

echo "Hello world!"

With this command, "Hello world!" is displayed on the screen.

But when you execute the same command inside a $(...), the standard input and output streams are in a subshell that doesn't interfere with the current shell connected to your keyboard and screen. In this case, the standard output is sent to the variable usr_name.

usr_name=$(echo "Hello world!")

With this command, you don't see anything at the screen, but if you want to display this message to the screen, you need to run:

echo "$usr_name"

A possible way to bypass this, is to sent the output to a special file called /dev/tty. So issuing:

usr_name=$(echo "Hello world!" > /dev/tty)

will leave the variable $usr_name empty and send "Hello world!" to the terminal, even if executed form the subshell. It is also possible to read a password from the subshell directly from the terminal. Try:

$(get_secret ${usr_name} < /dev/tty)

as far as I guess your code, since you don't provide the code of the function get_secret () or of the command get_secret.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for all update. The owner of encpass.sh recommended to add set -- before calling his encpass.sh. this corrected the problem. Best Regards, Guy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.