shell redirection

2010-02-02 Thread Stefan Miklosovic
hi

I have a shell script and I would like to do something like this

$ ./script.sh  somefile

After that, I can, just say, write content of that file on the screen.

I would like to know, how to do that in script, I dont know that
tricky redirection things ...

thanks a lot
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: shell redirection

2010-02-02 Thread Igor V. Ruzanov
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Tue, 2 Feb 2010, Stefan Miklosovic wrote:

|hi
|
|I have a shell script and I would like to do something like this
|
|$ ./script.sh  somefile
|
You could do kind of the following things:

example.sh:
#!/bin/sh

read new  /dev/stdin
echo $new

After your script was created, you could run it with some redirected 
text file:

./example.sh  file.txt

Don't forget about permissions of your script file to enable script 
execution. Also you might use while/for-expressions if content of the text 
file is multiple strings rather than just a big one.

+---+
! CANMOS ISP Network!
+---+
! Best regards  !
! Igor V. Ruzanov, network operational staff!
! e-Mail: ig...@canmos.ru   !
+---+
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: For info see http://quantumlab.net/pine_privacy_guard/

iD8DBQFLaD6Pbt6QiUlK9twRAhbCAJ4iXYyu5SZqc2uGQsg2tkzsIub+iACgv5l0
0RrvgPbvlfKc6HYm06MnWRk=
=4wLL
-END PGP SIGNATURE-
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Bourne shell redirection of STDOUT

2002-09-29 Thread parv

in message [EMAIL PROTECTED],
wrote Jimmy Lantz thusly...

 I wonder if anyone know a way to redirect the STDOUT directly to a
 variabel in a shellscript w/o using tempfile.

 I know I can use a tempfile but I'm looking for a way to avoid
 using a file.

you could use pipe (fifo) and/or, in bash2  ksh93, arrays.
a pipe is created by mkfifo(1); fill an array in a while loop.

(yeah i know, that doesn't answer your question of not using a file
in the bourne shell.)


  - parv

--


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-questions in the body of the message



Re: Bourne shell redirection of STDOUT

2002-09-29 Thread parv

in message [EMAIL PROTECTED],
wrote parv thusly...

 you could use pipe (fifo) and/or, in bash2  ksh93, arrays.
 a pipe is created by mkfifo(1); fill an array in a while loop.

argh, never mind... better suggestions already made.  sorry for the
noise...

-- 


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-questions in the body of the message



Bourne shell redirection of STDOUT

2002-09-28 Thread Jimmy Lantz

Hi,
I wonder if anyone know a way to redirect the STDOUT directly to a variabel 
in a shellscript w/o using tempfile.

I know I can use a tempfile but I'm looking for a way to avoid using a file.

in other words

Does anyone have an alternative to this? I would like to be able to run 
this script read-only :
#!/bin/sh
DIALOG=${DIALOG=/usr/bin/dialog}
dialog --inputbox Hitme 8 40  \
  2 /tmp/tempfile
myvar=`cat /tmp/tempfile`

Tia
Jim.


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-questions in the body of the message



Re: Bourne shell redirection of STDOUT

2002-09-28 Thread Mikko Työläjärvi

On Sat, 28 Sep 2002, Jimmy Lantz wrote:

 Hi,
 I wonder if anyone know a way to redirect the STDOUT directly to a variabel
 in a shellscript w/o using tempfile.

Use backticks ``.


 I know I can use a tempfile but I'm looking for a way to avoid using a file.

 in other words

 Does anyone have an alternative to this? I would like to be able to run
 this script read-only :
 #!/bin/sh
 DIALOG=${DIALOG=/usr/bin/dialog}
 dialog --inputbox Hitme 8 40  \
   2 /tmp/tempfile
 myvar=`cat /tmp/tempfile`

Aha.  You're not redirecting stdout, you want stderr, and backticks
will only get stdout (which you don't want, as it is used to present
the dialog).  Here are two possible solutions:

 1) Swap stdout and stderr:

myvar=`$DIALOG --inputbox Hitme 8 40 91 12 29`

 2) Since dialog will require a tty anyway, let it talk directly
to /dev/tty, and redirect stderr to stdout:

myvar=`$DIALOG --inputbox Hitme 8 40 21 /dev/tty`

   $.02,
   /Mikko


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-questions in the body of the message



Re: Bourne shell redirection of STDOUT

2002-09-28 Thread Oliver Fromme

Jimmy Lantz [EMAIL PROTECTED] wrote:
  Does anyone have an alternative to this? I would like to be able to run 
  this script read-only :
  #!/bin/sh
  DIALOG=${DIALOG=/usr/bin/dialog}
  dialog --inputbox Hitme 8 40  \
2 /tmp/tempfile
  myvar=`cat /tmp/tempfile`

Nice example of abuse of cat.  :-)

#!/bin/sh -
DIALOG=${DIALOG=/usr/bin/dialog}
myvar=$($DIALOG --inputbox Hitme 8 40 21 $(tty))

Regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH  Co KG, Oettingenstr. 2, 80538 München
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

All that we see or seem is just a dream within a dream (E. A. Poe)

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-questions in the body of the message