LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-13-2006, 09:20 PM   #1
stormrider_may
Member
 
Registered: Sep 2005
Distribution: Debian
Posts: 304

Rep: Reputation: 30
Shell-script question about getting a number as a variable


I have a little script. In it, i have to get a page where will be a number, that is very important to me.

like this...

Code:
lynx -dump http://192.168.0.2/venda_atual.php > temp.php
The problem is that when i see temp.php i get something like this.

Code:
   1670
Thatīs the number, but it have three spaces in front on it. Well, now let me put the script here and you will see my problem.

Code:
links http://192.168.0.2/venda.php
lynx -dump http://192.168.0.2/venda_atual.php > atual.tmp
venda=īhead -1 atual.tmpī
lynx -dump http://192.168.0.2/venda2.php?codigo=$venda > temp.php
lp temp.php
imprimir=$(
        dialog  --yesno '\n Deseja imprimir a venda novamente?'\
                --stdout \
                --backtitle 'Demorgan Unifomes LTDA.' \
                0 0 )
if [ $imprimir = 0 ]; then
       lp temp.php
fi
The problem is the second time when lynx run. It gets three spaces on the url, and thatīs a problem because it wonīt work at all.
What can i do?

Also, are there any syntax error in my script?
 
Old 03-13-2006, 10:08 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
If your shell is set up to have extglob on with shopt -s extglob, the following works:
Code:
$ venda="   1670"
$ echo "${venda##+([[:space:]])}"
1670
$
I haven't checked your script for errors...

Last edited by gilead; 03-13-2006 at 10:09 PM.
 
Old 03-13-2006, 10:49 PM   #3
stormrider_may
Member
 
Registered: Sep 2005
Distribution: Debian
Posts: 304

Original Poster
Rep: Reputation: 30
Well, looks like shell script hates me a lot.

This script donīt work

Code:
links http://192.168.0.2/programa/venda.php
lynx -dump http://192.168.0.2/venda_atual.php > atual.tmp
venda1=$(head -1 atual.tmp)
venda=${venda1##+([[:space:]])}
lynx -dump http://192.168.0.2/venda2.php?codigo=$venda > temp.php
lp temp.php
while : ; do
imprimir=$(
        dialog --stdout               \
               --title 'Demorgan Uniformes LTDA.'  \
               --menu 'Deseja imprimir a venda novamente?' \
              0 0 0                   \
              1 'Sim' \
              2 'Nco'  )
case "$imprimir" in
        1) break ;;
        2) /usr/bin/lp temp.php ;;
esac
done
Why those error happens?

Code:
Can't Access `file://localhost/root/1732%0D%0D'
Alert!: Unable to access document.

lynx: Can't access startfile
lp: unable to print file: client-error-bad-request
'usr/bin/programa_venda: line 15: syntax error near unexpected token `in
'usr/bin/programa_venda: line 15: `case "$imprimir" in
 
Old 03-13-2006, 10:55 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
Can you try it again after running shopt -s extglob at a bash prompt? If the extglob option isn't set, the +( ) part of the substitution won't be recognised.
 
Old 03-13-2006, 11:02 PM   #5
stormrider_may
Member
 
Registered: Sep 2005
Distribution: Debian
Posts: 304

Original Poster
Rep: Reputation: 30
I tried it, still not working...
 
Old 03-13-2006, 11:02 PM   #6
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Please try this:
Code:
links http://192.168.0.2/venda.php
lynx -dump http://192.168.0.2/venda_atual.php > atual.tmp
venda=`head -1 atual.tmp|awk '{print $1}'`
lynx -dump http://192.168.0.2/venda2.php?codigo=$venda > temp.php
lp temp.php
imprimir=$(
        dialog  --yesno '\n Deseja imprimir a venda novamente?'\
                --stdout \
                --backtitle 'Demorgan Unifomes LTDA.' \
                0 0 )
if [ $imprimir = 0 ]; then
       lp temp.php
fi
PS:
"set -x" can be your friend, too. for example:
Code:
links http://192.168.0.2/venda.php
lynx -dump http://192.168.0.2/venda_atual.php > atual.tmp
set -x
venda=`head -1 atual.tmp|awk '{print $1}'`
set +x
lynx -dump http://192.168.0.2/venda2.php?codigo=$venda > temp.php
lp temp.php
imprimir=$(
        dialog  --yesno '\n Deseja imprimir a venda novamente?'\
                --stdout \
                --backtitle 'Demorgan Unifomes LTDA.' \
                0 0 )
if [ $imprimir = 0 ]; then
       lp temp.php
fi

Last edited by paulsm4; 03-13-2006 at 11:05 PM.
 
Old 03-13-2006, 11:35 PM   #7
stormrider_may
Member
 
Registered: Sep 2005
Distribution: Debian
Posts: 304

Original Poster
Rep: Reputation: 30
Thanks for the help
Iīm still getting some errors. I hope you can help me.

Code:
request id is epsonlx300-9 (1 file(s))
: command not foundenda: line 10:

Error: Expected at least 3 tokens for --yesno, have 1.
Use --help to list options.


/usr/bin/programa_venda: line 12: --stdout: command not found
/usr/bin/programa_venda: line 13: --backtitle: command not found
/usr/bin/programa_venda: line 14: 0: command not found
/usr/bin/programa_venda: line 14: syntax error: unexpected end of file
 
Old 03-14-2006, 12:41 AM   #8
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
The first error tells you the basic problem:
Code:
Error: Expected at least 3 tokens for --yesno, have 1.
Use --help to list options.
So, for example, instead of:
Code:
dialog  --yesno '\n Deseja imprimir a venda novamente?' \
                --stdout \
                --backtitle 'Demorgan Unifomes LTDA.' \
0 0
... you need something like:
Code:
dialog  --yesno '\n Deseja imprimir a venda novamente?' 0 0 \
                --stdout \
                --backtitle 'Demorgan Unifomes LTDA.'
That is, you need "dialog --yesno <MYTEXT> <X> <Y>" all together.
 
Old 03-14-2006, 06:21 AM   #9
stormrider_may
Member
 
Registered: Sep 2005
Distribution: Debian
Posts: 304

Original Poster
Rep: Reputation: 30
paulsm4, it is complaining about it again

Code:
Error: Expected no more than 3 tokens for --yesno, have 4.
Use --help to list options.
 
Old 03-14-2006, 09:18 AM   #10
stormrider_may
Member
 
Registered: Sep 2005
Distribution: Debian
Posts: 304

Original Poster
Rep: Reputation: 30
Solved. Thanks for the help guys. The problem was in the text editor i was using. Somehow joe was fucking my script. When i changed to nano, everything got perfect.
I think this could be a bug on joe with portuguese language and simbols like "į".
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script and Dynamic variable xanthium Programming 11 07-12-2011 07:05 AM
Shell Script Random Variable Daniel Programming 14 12-03-2007 06:00 AM
Shell script --cannot assign variable-- ralvez Programming 6 02-24-2006 05:56 PM
Help with shell script, can't show variable stormrider_may Programming 5 01-27-2006 06:22 PM
Question about function with variable number of parameters xailer Programming 4 01-13-2004 12:37 PM


All times are GMT -5. The time now is 12:46 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration