Since you specify using bash shell we can flush the input buffer using:
so your script would look like this:
Hi Chubler_XL,
That might work with some versions of bash, but it won't work with 3.2.57 (which comes with the most recent release of macOS Mojave) since the read built-in in that version doesn't have a -N option. The loop you suggest above silently throws away the diagnostic saying there is no -N option and gives no indication that whatever was intended to be done by the while loop didn't do anything. The following read then reads the next available character no matter when it was typed.
Since darwin_866 has told us neither what OS is being used nor which version of bash is being used, we don't have any way to know if what you suggested might work in his/her environment.
I am trying to create a shell (ksh) which has two "read" commands, one which reads a line from a file and another which is inside a loop that reads user input from a keyboard. However, the "read" command inside the loop uses the input from the file and it does not get the user input from keyboard.... (3 Replies)
Hello all,
How can i have a user input that reads like this:
echo -n "Please enter a & b:" 10 20
read a
read b
echo $a
echo $b
10
20
right now i have divided it into two echos, like
echo -n "a: "
echo -n "b: " (1 Reply)
I'm trying to set up a script that takes user input and validates that the user input was entered correctly.
So far I have this:
while :
do
echo "Please enter your name."
read NAME
if
then
echo "You have not entered a name."
echo... (13 Replies)
If I want all user input to start with " : " if not display error
or what I asking is how to do if statement that control a first letter of string that we want to start with. and not worry about the rest
Thank (1 Reply)
Hi,
echo "Enter file name of input file list along with absolute path : "
read inputFileList
if
then
for string in `cat inputFileList`
do
echo $string
done
else
echo " file does not exist"
fi
From the above code, if the user enters a invalid file... (1 Reply)
i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled.
#!/bin/sh
echo " Enter your choice to continue y/Y OR n/N to quit "
read A
if
then
echo " user requested to continue "
##some commands... (7 Replies)
$Input_filename=$ARGV;
if (!-d $Input_filename && ! -e $Input_filename)
{
print "USAGE: Please enter '$ABCD/def/dsed.txt' as an arguement \n";
exit;
}
1. Input Is suppose to be something like "$ABCD/def/dsed.txt".
if the input is wrong the script should throw an ERROR message.... (2 Replies)
Why does removing "rhgb quiet" from the kernel boot parameters control whether or not the commands I enter are displayed in single user mode ?
For instance, if I do not remove "rhgb quiet", when I am in single user mode, whatever command I type will not be displayed on the screen.
The... (0 Replies)
I am trying to allow a user to enter in text and then store that text in a variable $gene to run in an awk command in which those values are used to run some calculations. I am getting syntax errors however, when I try. Thank you :).
The awk runs great if it is a pre-defined file that is used,... (7 Replies)
Discussion started by: cmccabe
7 Replies
LEARN ABOUT REDHAT
which
WHICH(1) General Commands Manual WHICH(1)NAME
which - shows the full path of (shell) commands.
SYNOPSIS
which [options] [--] programname [...]
DESCRIPTION
Which takes one or more arguments. For each of its arguments it prints to stdout the full path of the executables that would have been exe-
cuted when this argument had been entered at the shell prompt. It does this by searching for an executable or script in the directories
listed in the environment variable PATH using the same algorithm as bash(1).
This man page is generated from the file which.texinfo.
OPTIONS --all, -a
Print all matching executables in PATH, not just the first.
--read-alias, -i
Read aliases from stdin, reporting matching ones on stdout. This is useful in combination with using an alias for which itself. For
example
alias which='alias | which -i'.
--skip-alias
Ignore option `--read-alias', if any. This is useful to explicity search for normal binaries, while using the `--read-alias' option in
an alias or function for which.
--read-functions
Read shell function definitions from stdin, reporting matching ones on stdout. This is useful in combination with using a shell func-
tion for which itself. For example:
which() { declare -f | which --read-functions $@ }
export -f which
--skip-functions
Ignore option `--read-functions', if any. This is useful to explicity search for normal binaries, while using the `--read-functions'
option in an alias or function for which.
--skip-dot
Skip directories in PATH that start with a dot.
--skip-tilde
Skip directories in PATH that start with a tilde and executables which reside in the HOME directory.
--show-dot
If a directory in PATH starts with a dot and a matching executable was found for that path, then print "./programname" rather than the
full path.
--show-tilde
Output a tilde when a directory matches the HOME directory. This option is ignored when which is invoked as root.
--tty-only
Stop processing options on the right if not on tty.
--version,-v,-V
Print version information on standard output then exit successfully.
--help
Print usage information on standard output then exit successfully.
RETURN VALUE
Which returns the number of failed arguments, or -1 when no `programname' was given.
EXAMPLE
The recommended way to use this utility is by adding an alias (C shell) or shell function (Bourne shell) for which like the following:
[ba]sh:
which ()
{
(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@
}
export -f which
[t]csh:
alias which 'alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
This will print the readable ~/ and ./ when starting which from your prompt, while still printing the full path when used from a script:
> which q2
~/bin/q2
> echo `which q2`
/home/carlo/bin/q2
BUGS
The HOME directory is determined by looking for the HOME environment variable, which aborts when this variable doesn't exist. Which will
consider two equivalent directories to be different when one of them contains a path with a symbolic link.
AUTHOR
Carlo Wood <carlo@gnu.org>
SEE ALSO bash(1)WHICH(1)