Here is another way to do it:
#!/bin/bash
# Read Password
echo -n Password:
read -s password
echo
# Run Command
echo $password
The read -s
will turn off echo for you. Just replace the echo
on the last line with the command you want to run.
More Related Contents:
- How can I declare and use Boolean variables in a shell script?
- Are shell scripts sensitive to encoding and line endings?
- Difference between sh and Bash
- Correct Bash and shell script variable capitalization
- Pass commands as input to another command (su, ssh, sh, etc)
- Why would a correct shell script give a wrapped/truncated/corrupted error message? [duplicate]
- Why is testing “$?” to see if a command succeeded or not, an anti-pattern?
- Reading quoted/escaped arguments correctly from a string
- Why equal to operator does not work if it is surrounded by space?
- How can I remove the extension of a filename in a shell script?
- sudo echo “something” >> /etc/privilegedFile doesn’t work [duplicate]
- Test for non-zero length string in Bash: [ -n “$var” ] or [ “$var” ]
- How do I run a shell script without using “sh” or “bash” commands?
- How can I suppress all output from a command using Bash?
- Ubuntu says “bash: ./program Permission denied” [closed]
- Assignment of variables with space after the (=) sign?
- How to get the part of a file after the first line that matches a regular expression
- How to redirect output of an entire shell script within the script itself?
- How does Ctrl-C terminate a child process?
- Deleting lines from one file which are in another file
- source command not found in sh shell
- Copy folder recursively, excluding some folders
- What does it mean in shell when we put a command inside dollar sign and parentheses: $(command)
- Passing arguments by reference
- Get just the filename from a path in a Bash script [duplicate]
- How to resolve symbolic links in a shell script
- Why equal to operator does not work if it is not surrounded by space?
- Is there an elegant way to store and evaluate return values in bash scripts?
- Extract version number from a string
- What does `kill -0 $pid` in a shell script do?