Hello.
I'm trying to automate a script in ksh using a here document, but need to enter the space bar between two commands. Is there any way I can achieve this?
command1 < EOF command2 space bar command3 EOF
How do I translate the space bar? I tried \r, \n, " " but no luck.
TIA, Nadeem.
On 09/17/2009 05:12 PM, Nadeem M. Khan wrote:
Hello.
I'm trying to automate a script in ksh using a here document, but need to enter the space bar between two commands. Is there any way I can achieve this?
command1< EOF command2 space bar command3 EOF
How do I translate the space bar? I tried \r, \n, " " but no luck.
Ummm, the literal space (" ") character doesn't work ? ...before command3 (as in ") command3" or after command2 (as in "command2 ") ?
btw, what is a 'here' document ?
cheers, - steve
On Thursday 17 Sep 2009, steve wrote:
[snip] Ummm, the literal space (" ") character doesn't work ? ...before command3 (as in ") command3" or after command2 (as in "command2 ") ?
Not clear on what the OP wants, so no comment here.
btw, what is a 'here' document ?
A here document is a shell construct by which you can simulate redirection from a file on the command-line. For instance, if you wanted to copy the following text to a floppy:
This is the house that Jack built. This is the malt that lay in the house that Jack built.
you can put it into a file, say /tmp/file.txt, then:
cat < /tmp/file.txt > /dev/fd0
If you want to avoid the intermediate step of creating file.txt, you can use a here document with the content you want:
cat > /dev/fd0 <<some_string This is the house that Jack built. This is the malt that lay in the house that Jack built. some_string
The effect is as if you had put the text between some_string...some_string in a file and redirected stdin from that file, except that no actual file is created. Convenient for quick-and-dirty texts, specially stuff you copy-paste from some application.
Regards,
-- Raju
On 09/17/2009 11:31 PM, Raj Mathur wrote:
On Thursday 17 Sep 2009, steve wrote:
btw, what is a 'here' document ?
A here document is a shell construct by which you can simulate redirection from a file on the command-line. [...snip...] cat> /dev/fd0<<some_string This is the house that Jack built. This is the malt that lay in the house that Jack built. some_string
The effect is as if you had put the text between some_string...some_string in a file and redirected stdin from that file, except that no actual file is created. Convenient for quick-and-dirty texts, specially stuff you copy-paste from some application.
Oh ok ! thanks ! I've known and used the concept for such a long time without knowing that it had a name !
cheers, - steve
On Thu, Sep 17, 2009 at 10:01 PM, Raj Mathur raju@linux-delhi.org wrote:
On Thursday 17 Sep 2009, steve wrote:
[snip] Ummm, the literal space (" ") character doesn't work ? ...before command3 (as in ") command3" or after command2 (as in "command2 ") ?
Not clear on what the OP wants, so no comment here.
Raj, I thought I was pretty clear in explaining what I needed. Let me give an example of how a sample script works with user intervention, and then without user intervention, autmated by here documents.
With user intervention:
#samplescript.ksh Are you sure you want to continue (y/n) ? y Enter number of blah blah[1-1000] 500 Hit the space bar to continue: I have to hit space bar here Are these setting correct? (y/n) y #
Without user intervention using here documents:
#samplescript.ksh <<EOF y 500 this line is where I need the list's help y EOF
Thanks, Nadeem.
On Sun, Sep 20, 2009 at 10:00 AM, Nadeem M. Khan nadeem.m.khan@gmail.comwrote:
On Thu, Sep 17, 2009 at 10:01 PM, Raj Mathur raju@linux-delhi.org wrote:
On Thursday 17 Sep 2009, steve wrote:
[snip] Ummm, the literal space (" ") character doesn't work ? ...before command3 (as in ") command3" or after command2 (as in "command2 ") ?
Not clear on what the OP wants, so no comment here.
Raj, I thought I was pretty clear in explaining what I needed. Let me give an example of how a sample script works with user intervention, and then without user intervention, autmated by here documents.
With user intervention:
#samplescript.ksh Are you sure you want to continue (y/n) ? y Enter number of blah blah[1-1000] 500 Hit the space bar to continue: I have to hit space bar here Are these setting correct? (y/n) y #
Without user intervention using here documents:
#samplescript.ksh <<EOF y 500 this line is where I need the list's help y EOF
Thanks, Nadeem. -- http://mm.glug-bom.org/mailman/listinfo/linuxers
You can save these thing in file and apply a redirection ,
$samplescript.ksh < test.txt
I am attaching file. Hope it will work,.
On Sunday 20 Sep 2009, Nadeem M. Khan wrote:
On Thu, Sep 17, 2009 at 10:01 PM, Raj Mathur raju@linux-delhi.org
wrote:
On Thursday 17 Sep 2009, steve wrote:
[snip] Ummm, the literal space (" ") character doesn't work ? ...before command3 (as in ") command3" or after command2 (as in "command2 ") ?
Not clear on what the OP wants, so no comment here.
Raj, I thought I was pretty clear in explaining what I needed. Let me give an example of how a sample script works with user intervention, and then without user intervention, autmated by here documents.
With user intervention:
#samplescript.ksh Are you sure you want to continue (y/n) ? y Enter number of blah blah[1-1000] 500 Hit the space bar to continue: I have to hit space bar here Are these setting correct? (y/n) y
Presumably the script is using a dummy "read" shell built-in to read the space bar. If that is the case, an empty line in the input (or a line containing anything at all) will do the job. Something like this in the script:
echo -n "Are you sure (y/n)? " read yn if [ "$yn" = "y" ]; then ... fi echo -n "Enter number: " read num echo -n "Hit space to continue: " read __dummy ...
If the script is actually reading the space bar (and not a whole line) then it looks like it's using some program to put the keyboard into raw mode (as opposed to cooked, line-by-line mode), in which case you'd have to check exactly how the input is being read so you can feed it through the here document. Can't say more without seeing the actual script.
Regards,
-- Raju
On Sun, Sep 20, 2009 at 7:57 PM, Raj Mathur raju@linux-delhi.org wrote:
echo -n "Hit space to continue: " read __dummy
it could be something like this #!/bin/bash ... ... echo -n "Hit space to continue" read -n 1 dummy
Which will cause bash to return after exactly one char is entered
Regards Manvendra http://www.indimail.org
On Sunday 20 Sep 2009, Manvendra Bhangui wrote:
On Sun, Sep 20, 2009 at 7:57 PM, Raj Mathur raju@linux-delhi.org
wrote:
echo -n "Hit space to continue: " read __dummy
it could be something like this #!/bin/bash ... ... echo -n "Hit space to continue" read -n 1 dummy
Which will cause bash to return after exactly one char is entered
That makes sense, in which case, if you have something like:
read num read -n 1 dummy read yn
you can run the script as:
... <<EOF 100 dy EOF
so num gets the value "100", dummy gets the value "d" and yn gets the value "y".
Regards,
-- Raju
On Sun, Sep 20, 2009 at 11:44 PM, Raj Mathur raju@linux-delhi.org wrote:
On Sunday 20 Sep 2009, Manvendra Bhangui wrote:
On Sun, Sep 20, 2009 at 7:57 PM, Raj Mathur raju@linux-delhi.org
wrote:
echo -n "Hit space to continue: " read __dummy
it could be something like this #!/bin/bash ... ... echo -n "Hit space to continue" read -n 1 dummy
Which will cause bash to return after exactly one char is entered
That makes sense, in which case, if you have something like:
read num read -n 1 dummy read yn
you can run the script as:
... <<EOF 100 dy EOF
so num gets the value "100", dummy gets the value "d" and yn gets the value "y".
Thanks for the help. I must admit I was unclear. The task I am trying to automate is a built-in HP-UX utility which asks me lots of questions. I am required to repeat running this utility with answers to all questions except one being constant. Thats where I thought of creating a shell script with a here doc.
Unfortunately, the HP-UX utility is not a script - its a binary. I don't have access to my VPN right now so can't test the suggestions given by listers. I'll keep you informed.
Thanks again, Nadeem.
On Thu, Sep 17, 2009 at 3:50 PM, steve steve@lonetwin.net wrote:
On 09/17/2009 05:12 PM, Nadeem M. Khan wrote:
command1< EOF command2 space bar command3 EOF
How do I translate the space bar? I tried \r, \n, " " but no luck.
Ummm, the literal space (" ") character doesn't work ? ...before command3 (as in ") command3" or after command2 (as in "command2 ") ?
Thanks Steve, I had tried that earlier without luck.
Nadeem.