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 Fri 21 Nov 2014, 15: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 Posts_count  
Author Message
Argolance


Joined: 06 Jan 2008
Posts: 1844
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.

Edited_time_total
Back to top
View user's profile Send_private_message Visit_website 
L18L

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

PostPosted: Thu 18 Apr 2013, 05:36    Post_subject: [: too many arguments
Sub_title: 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: 1844
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_website 
L18L

Joined: 19 Jun 2010
Posts: 2574
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_website 
Argolance


Joined: 06 Jan 2008
Posts: 1844
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   257 Time(s)

144532_582x183_easyshot.jpg

Back to top
View user's profile Send_private_message Visit_website 
Bruce B


Joined: 18 May 2005
Posts: 11131
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: 522
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_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0692s ][ Queries: 12 (0.0037s) ][ GZIP on ]