Heya people,
So my script is one of those make-user-scripts, making a bunch of directories in the home folder and copying some files over into the new directories.
However, part of the thing my script need to do is check the home folder if a username matches with a directory which already exists.
e.g. if the username 'user1' has a directory in the home folder under the same name, it will prompt the user if he/she wants to keep or delete the directory (and its contents) before moving on with the script.
Here is the part of the script which does this:
Where:
$1 = path to the username_list file
$4 = path to the home directory for user creation
Now as the thread title suggests, the problem is the read line is not prompting for user input.
I suspect it may be something to do with the fact I'm piping via the while loop, but I don't know I'm just a newbie to all this. Can anyone suggest a solution to this?
You've got two reads in your code snippet; which one does not operate the way you'd expect it to? In your question text, you name the read line, but this one is not prompting, whilst the other, prompting one is read answer.
Please look again at your script and guess/find out where the second read is redirected to; you may find the answer by yourself.
And, BTW, it doesn't help a little bit either to give snappy answers to people offering help...
In case you are not aware, the redirections that affect the while-loop statement are inherited by all of the commands within it. So, in your case, the pipe between cat and while-read redirects the standard input of the entire while-loop to cat's output. Both of your read commands will be taking their input from cat. Line 1 from cat will be consumed by the first read statement. Line 2 from cat will be consumed by the second read statement, etc. Is that intentional? I assume it's not, since if that were the case, there would be no need to prompt cat for a response.
That way you don't have the "read inside a read loop issue" that alister pointed out. BTW well spotted alister - that one didn't register with me but once you pointed it out it seemed the best way to fix the script was to have an outer loop not using reads so the inner loop could issue reads.
Hope this helps.
-Andy.
Last edited by mcp; 03-29-2013 at 05:51 PM..
Reason: Spelt loop as look - D'Oh!
Hi,
I am working on a script, which requests users to enter input.
Ex: read -p "Please enter your email id:" email
I don't want users skipping this entry, this has to be mandatory.I dont want to proceed without input.
I can do a check if variable $email is empty and proceed if not.But, i... (7 Replies)
Hello,
I want to use the read command in order to input a keyword from the keyboard.
I then want to use this keyword in a grep command.
How to I input a phrase as a keyword? For example if I use
read keyword
"today is"
and then use grep, I get "No such file or directory" error. (6 Replies)
Dear Friends,
I am looking for a shell script to merge input files into one file .. here is my idea:
1st paramter would be outfile file (all input files content)
read all input files and merge them to input param 1
ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
My script needs to get some input from the user and go as a background process and run.
I have something like
read input.
do
while ...
if
..
fi
done
can i use nohup inside the script?? (7 Replies)
Hi
I am new to writing script and want to use a Bash Piped while-read and read from user input.
if something happens on server.log then do while loop or if something happend on user input then do while loop.
Pseudocode something like:
tail -n 3 -f server.log | while read serverline || read... (8 Replies)
I have a script.
#! /bin/bash
echo "Enter a word: "
read word
echo $word
That outputs like this..
Enter a word:
hello
hello
But how can i read on the same line the question is printed?
Like this..
Enter a word: hello
hello (2 Replies)
echo "enter employee #:/c"
read employee
grep -w $employee /tmp/file.txt
when it asked me employee #, i typed employee, worked fine.
when it asked me employee #, i type ENTER, it just sit there.
if someone type in NULL or ENTER key, i want to exit out. (2 Replies)
Can anyone tell me why this section of my script doesn't work? The script is designed to accept piped data, store it in a temporary location, and then prompt the user for their user name. It doesn't stop to read the username, however. It just finishes.
It is called like:
cat datafile | myscript... (3 Replies)
hello all, I have a script (Solaris v8 ksh) monitoring an inbound directory for reports. The script will then capture the report based on a set of circumstances. However I am unable to capture a report larger then 2-Gig in size due to program limitations. What I need to do is pause the monitor... (6 Replies)