Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 30 Sep 2014, 10:34
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
[: too many arguments [SOLVED]
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [9 Posts]  
Author Message
Argolance


Joined: 06 Jan 2008
Posts: 1830
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Thu 18 Apr 2013, 04:56    Post subject:  [: too many arguments [SOLVED]  

Bonjour,
Sometimes, but not always Shocked , xerrs.log returns:
Quote:
myscript.sh: line xx: [: too many arguments

... in this case for example, where the script verify if /root/Desktop directory exists or not and create it if not:
Code:
if [ ! -d /root/Desktop ]; then
mkdir /root/Desktop
Xdialog --title "xxxx" --icon /usr/local/lib/X11/pixmaps/question.png --msgbox "xxxxx" 0 0
fi

This works but I would like to understand what's wrong or seems to be so.

Thank you!

Cordialement.

Last edited by Argolance on Thu 18 Apr 2013, 08:44; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
L18L

Joined: 19 Jun 2010
Posts: 2507
Location: Moved from Hosla to www.eussenheim.de

PostPosted: Thu 18 Apr 2013, 05:36    Post subject: [: too many arguments
Subject description: too less info
 

Bonjour Argolance,
I have been trying to understand how to help you but no success so far Embarassed
Please post a concrete example of
error wrote:
: [: too many arguments

Cordialment Wink
Back to top
View user's profile Send private message 
Argolance


Joined: 06 Jan 2008
Posts: 1830
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Thu 18 Apr 2013, 07:16    Post subject:  

Hello L18L,
Thank you for replying.
I solved this issue by writing:
Code:
if [[ ! -f /root/Desktop/*.desktop ]]; then
But this is quite strange indeed, because my script has other conditional lines that are exactly built the same way... and xerrs.log doesn't complain! Shocked
Code:
if [ ! -d /root/Desktop ]; then
mkdir /root/Desktop
Xdialog --title "$(gettext 'Information')" --icon /usr/local/lib/X11/pixmaps/question.png --msgbox "$(gettext '"Desktop" directory, where wine copies
the desktop MENU entries files of its installed programs has been created!')" 0 0
else
echo "$(ls /root/Desktop/*.desktop)" > /root/test
fi
if [[ ! -f /root/Desktop/*.desktop ]]; then
Xdialog --title "$(gettext 'Information')" --icon /usr/local/lib/X11/pixmaps/info.png --msgbox "$(gettext '"Desktop" directory is empty and there are no desktop MENU entry file to modify/complete!')" 0 0
else
...
And the best is that this can change as I am building my script....
At the beginning, xerrs.log said nothing, suddenly complained about the first conditional lines, then the second and now, writing double "[", it is mute and happy! Very Happy
EDIT: ... But the first conditional lines doesn't work properly anymore! Embarassed

Cordialement.
Back to top
View user's profile Send private message Visit poster's website 
L18L

Joined: 19 Jun 2010
Posts: 2507
Location: Moved from Hosla to www.eussenheim.de

PostPosted: Thu 18 Apr 2013, 07:30    Post subject:  

So it is about diffrence of [ and [[ (one or two [)

I have no .desktop in my /root/Desktop an run your
# if [[ ! -f /root/Desktop/*.desktop ]]; then echo no;else echo yes; fi
no
#

changing to one [ :
# if [ ! -f /root/Desktop/*.desktop ]; then echo no;else echo yes; fi
bash: [: too many arguments
yes
#

Arrow Never ignore the error message, result is wrong if error Idea
Very Happy
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Thu 18 Apr 2013, 08:11    Post subject:  

Code:
bash-3.00# [[ -f /usr/share/applications/*.desktop ]] && echo Y || echo N
N

Then use
Code:
[ "`ls -1 /usr/share/applications/*.desktop`" ] && echo Y || echo N


Note : If the variable may contain spaces, the "double quoting inside the single [ brackets are needed .
Note : I tend to quote them always, just in case - though it looks better in default geany .sh template without the double quotes.
Note : BK double quotes a lot of strings, where in 99% of the cases no double quotes are needed but tends to omit them many times in test lines .
Note : [ "$*" ] && ALL_PARAMETERS="$@"
Code:
function_test(){
[ "$@" ] && P1="$@"
[ "$*" ] && P2="$@"
[ "$*" ] && P3="$*"
echo "P1='$P1'"
echo "P2='$P2'"
echo "P3='$P3'"
}
function_test -d/dev/sdz99 --quiet "/path / to -f /filename"
Back to top
View user's profile Send private message Visit poster's website 
Argolance


Joined: 06 Jan 2008
Posts: 1830
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Thu 18 Apr 2013, 08:44    Post subject:  

Thanks to both of you!

Cordialement.
144532_582x183_easyshot.jpg
 Description   
 Filesize   22.72 KB
 Viewed   253 Time(s)

144532_582x183_easyshot.jpg

Back to top
View user's profile Send private message Visit poster's website 
Bruce B


Joined: 18 May 2005
Posts: 11109
Location: The Peoples Republic of California

PostPosted: Thu 18 Apr 2013, 22:10    Post subject:  

I wrote the snippet below. If there are any .txt files in the current directory, the return code is 0. If not the return code is 1

The 2>/dev/null hides the text error output if no .txt files are found.

Code:
[ "`ls -la *.txt 2>/dev/null`" ] ; echo $?


Question: Maybe Karl or someone will explain to me why the quotes are necessary to make the [ test ] work properly. I mean, how or why do the quotes work?


TIA

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
Ibidem

Joined: 25 May 2010
Posts: 493
Location: State of Jefferson

PostPosted: Fri 19 Apr 2013, 01:45    Post subject:  

Bruce B wrote:
I wrote the snippet below. If there are any .txt files in the current directory, the return code is 0. If not the return code is 1

The 2>/dev/null hides the text error output if no .txt files are found.

Code:
[ "`ls -la *.txt 2>/dev/null`" ] ; echo $?


Question: Maybe Karl or someone will explain to me why the quotes are necessary to make the [ test ] work properly. I mean, how or why do the quotes work?

Because if there is more than one parameter, test ([) assumes that it's supposed to have an option. The double quotes make test see all the output as one parameter.
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3972
Location: Kiel,Germany

PostPosted: Fri 19 Apr 2013, 05:54    Post subject:  

And it seems not to be because of just spaces but for the common IFS FileSeparator since ls -1 would use newline . Will test things with other IFS set .

The common file separator is " \t\n" .

_________________
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal Razz
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [9 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0699s ][ Queries: 13 (0.0040s) ][ GZIP on ]