Re: simple scripts made difficult? :)
andrej hocevar wrote:
>hello
>i'm just begining to write very simple scripts and came along these two
>problems.
>i) how do i (re)direct an output to a file and at the same time see
>it as usual on screen?
some_command | tee filename
You can also use script to capture an entire session.
>ii) how do i pass a simple argument from a file or an output to a script
>that's just testing it, eg. a file has two arguments, now i want to pass
>it to a script that takes the first one and echoes it on screen?
In the script, the command line parameters are $1, $2, etc. The output
of a command can be put into a command line by using backquotes or $():
myscript `mycommand_that_outputs_two_words`
Then the script:
#!/bin/bash
# myscript -- echoes the first argument
if [ -z "$1" ]
then
echo No arguments supplied"
exit 1
else
echo $1
fi
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"For whosoever shall call upon the name of the Lord
shall be saved." Romans 10:13
Reply to: