Sponsored Content
Top Forums Shell Programming and Scripting Nonblocking I/O in bash scripts Post 302245706 by neked on Friday 10th of October 2008 06:39:29 PM
Old 10-10-2008
Pretty damn cool cfajohnson.

Here is my implementation based on your stty idea and some modifications:

Code:
#!/bin/bash

if [ -t 0 ]; then
    stty -echo -icanon time 0 min 0
fi;

read line
echo "The input was, if any: " $line

if [ -t 0 ]; then
    stty sane
fi;

if that code was saved in an executable named test.sh, then you could do the following:

Code:
bash$ ./test.sh
The input was, if any: 
bash$ echo "test" | ./test.sh
The input was, if any: test

The reason I'm using the if [ -t 0 ]; statement is to make sure that standard input is coming from the terminal, not a pipe, otherwise you'll get annoying errors:
Code:
stty: standard input: Invalid argument

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Bash Shell Scripts

Hi all, plz can anybody tell me that if a script written for Bash shell also work for other shells and if yes , how ??? Thanks and Regards SONAL (2 Replies)
Discussion started by: sonbag_pspl
2 Replies

2. Shell Programming and Scripting

GUI for bash scripts?

Hello everyone! I'm looking for a way to build a GUI for various bash scripts I've written. Is there any "good" way to do it? I've heard about python/gtk+,qt and other stuff, but I've absolutely no idea where I should look at. Thanks a lot in advance! Regards, xenator EDIT: ... (1 Reply)
Discussion started by: xenator
1 Replies

3. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

4. Homework & Coursework Questions

Bash shell scripts

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Test that exactly one command line argrument is enter from the command line. If not, display the usage... (1 Reply)
Discussion started by: jcoop12
1 Replies

5. Shell Programming and Scripting

Bash scripts as commands

Hello, the bulk of my work is run by scripts. An example is as such: #!/bin/bash awk '{print first line}' Input.in > Intermediate.ter awk '{print second line}' Input.in > Intermediate_2.ter command Intermediate.ter Intermediate_2.ter > Output.out It works the way I want it to, but it's not... (1 Reply)
Discussion started by: Leo_Boon
1 Replies

6. Shell Programming and Scripting

Parallel bash scripts

Need some help to replace bash script with parallel to speed up job on multiple files (400files.list is the file contains the absolute path to those 400 files). The bash script is to run the same program over the files repetitively. My bash_script.sh is: for sample in `cat 400files.list`; do... (3 Replies)
Discussion started by: yifangt
3 Replies

7. Shell Programming and Scripting

Merge two bash scripts

I am currently running the following two bash scripts, in order to start x, matchbox and midori on the raspberry pi hdmi, using a remote ssh session. start-browser #!/bin/bash # import variables source /var/rpi/scripts/config/variables/general echo "starting browser" DISPLAY=:0.0 sudo xinit... (2 Replies)
Discussion started by: aristosv
2 Replies

8. Shell Programming and Scripting

Bash -c interactive scripts

i have to run the following script through a pipe: script.sh: #!/bin/bash echo "Hello World" echo -e "The \033 here's how its currently being run: bash -c "$(cat script.sh)" This is an interactive script. the problem is, when i run it this way, if you go to another terminal and... (4 Replies)
Discussion started by: SkySmart
4 Replies

9. UNIX for Beginners Questions & Answers

Running scripts in bash

So I've written my first bash script.I wanted to run it from the command line, but I got an error: $ myscript.sh myscript.sh: command not found So instead I try this and it works: $ ./myscript.sh Is this how I will always need to execute it? How can I run myscript.sh without having to... (2 Replies)
Discussion started by: P.K
2 Replies
Prophet::Test(3pm)					User Contributed Perl Documentation					Prophet::Test(3pm)

   set_editor($code)
       Sets the subroutine that Prophet should use instead of "Prophet::CLI::Command::edit_text" (as this routine invokes an interactive editor)
       to $code.

   set_editor_script SCRIPT
       Sets the editor that Proc::InvokeEditor uses.

       This should be a non-interactive script found in t/scripts.

   import_extra($class, $args)
   in_gladiator($code)
       Run the given code using Devel::Gladiator.

   repo_path_for($username)
       Returns a path on disk for where $username's replica is stored.

   repo_uri_for($username)
       Returns a file:// URI for $USERNAME'S replica (with the correct replica type prefix).

   replica_uuid
       Returns the UUID of the test replica.

   database_uuid
       Returns the UUID of the test database.

   replica_last_rev
       Returns the sequence number of the last change in the test replica.

   as_user($username, $coderef)
       Run this code block as $username.  This routine sets up the %ENV hash so that when we go looking for a repository, we get the user's repo.

   replica_uuid_for($username)
       Returns the UUID of the given user's test replica.

   database_uuid_for($username)
       Returns the UUID of the given user's test database.

   ok_added_revisions( { CODE }, $numbers_of_new_revisions, $msg)
       Checks that the given code block adds the given number of changes to the test replica. $msg is optional and will be printed with the test
       if given.

   serialize_conflict($conflict_obj)
       Returns a simple, serialized version of a Prophet::Conflict object suitable for comparison in tests.

       The serialized version is a hash reference containing the following keys:
	   meta => { original_source_uuid => 'source_replica_uuid' }
	   records => { 'record_uuid' =>
			  { change_type => 'type',
			    props => { propchange_name => { source_old => 'old_val',
							    source_new => 'new_val',
							    target_old => 'target_val',
							  }
				     }
			  },
			'another_record_uuid' =>
			  { change_type => 'type',
			    props => { propchange_name => { source_old => 'old_val',
							    source_new => 'new_val',
							    target_old => 'target_val',
							  }
				     }
			  },
		      }

   serialize_changeset($changeset_obj)
       Returns a simple, serialized version of a Prophet::ChangeSet object suitable for comparison in tests (a hash).

   run_command($command, @args)
       Run the given command with (optionally) the given args using a new Prophet::CLI object. Returns the standard output of that command in
       scalar form or, in array context, the STDOUT in scalar form *and* the STDERR in scalar form.

       Examples:

	   run_command('create', '--type=Foo');

   load_record($type, $uuid)
       Loads and returns a record object for the record with the given type and uuid.

   as_alice CODE, as_bob CODE, as_charlie CODE, as_david CODE
       Runs CODE as alice, bob, charlie or david.

perl v5.10.1							    2009-09-02							Prophet::Test(3pm)
All times are GMT -4. The time now is 05:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy