Jean-Pierre Thibert wrote:
> Hi everybody and happy new year,
>> I'm learning shell script and have some questions. Could you help me?
The best book I have read on this is "Classic Shell Scripting" by Arnold
Robbins and Nelson Beebe. Strongly recommended (I forgot to say this
when we were talking in the pub before Christmas).
> 1)I have a variable with a value between 00.00 to 100.00 (ie : 12.58)
> I want to extract the integer. Something like X=int(MYVAR)
Bash doesn't support floating-point math _per se_, so it will think of
this as a string. See man bash and read about arithmetic evaluation and
arithmetic expansion.
> How to do that? I didn't find out after a lot of research.
Here's another (dirty) solution:
X=`echo $MYVAR | awk -F. '{print $1}'`
There are others, eg
X=`echo $MYVAR | sed -e "s+\..*$++"`
> 2) I think wget command has an output only as a file not a variable.
> Am I right?
The man page says:
-O file
--output-document=file
The documents will not be written to the appropriate files, but all
will be concatenated together and written to file. If - is used as
file, documents will be printed to standard output, disabling link
conversion. (Use ./- to print to a file literally named -.)
but I find this does not work: wget -O - http://www.google.ie saves the
output in a file called "-".
To pipe a URI into further commands, use dog (a replacement for cat, ha
ha)...if it's not installed, sudo apt-get install dog should do it. Then
you can type
dog --no-header http://www.google.ie | more stuff
> 3) I tried to find a script commands reference on Internet and a
> detailed training unsuccessfully.
> Have you some good links?
That book is the best place to start.
///Peter
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!