Press "Enter" to skip to content

Shell Script Example to Prompt for a Password in Linux

In Linux, use read command with -s option to read, hide and store password into a variable. Below is a shell script example, in which it will prompt for a password for Oracle database user SYSTEM, and after logging into the database, it will display the version information of Oracle.

Shell Script Example to Prompt for a Password

prompt_password.sh

#!/bin/bash
echo "Enter password for user System: "
read -s system_pw
sqlplus -S system/$system_pw@//YourIP/orcl << EOF
set pagesize 0 linesize 80 feedback off

SELECT BANNER
  FROM v$version;
  
Exit;
EOF

exit

Test

$ ./prompt_password.sh

Output

Enter password for user System: 
_
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE	11.2.0.1.0	Production
TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

See also:

Vinish Kapoor

Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. foxinfotech.in is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *