Bash too many arguments error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash too many arguments error
# 1  
Old 01-02-2011
Bash too many arguments error

Hello, I've got this little script that gets a bunch of comics and puts them in an html file. However, when I check that the comic URL is there and that it's a new one, I get the "too many arguments" error. The script is this:

Code:
CADURL=`curl --silent http://www.cad-comic.com/cad/ | grep -o 'http://cdn.cad-comic.com/comics/.*.jpg'`
COMICJKURL=`curl --silent http://comicjk.com/comic.php/latest | grep -o '../Pics/.*\.gif' | sed 's|\.\.|http://comicjk.com|g'`
BUGURL=`curl --silent http://www.bugcomic.com/ | grep -o 'http://www.bugcomic.com/comics/.*.png'`
XKCDURL=`curl --silent http://www.xkcd.com/ | grep -o 'http://imgs.xkcd.com/comics/.*.png' | head -1`
DILBERTURL=`curl --silent http://www.dilbert.com/ | grep -o 'http://dilbert.com/dyn/str_strip/.*/.*/.*/.*/.*/.*/.*/.*/.*\.strip\..*\gif'`
CYANIDEURL=`curl --silent -L http://www.explosm.net/comics/new/ | grep -o 'http://www.explosm.net/db/files/Comics/.*/.*.png'`
HIJINKSURL=`curl --silent http://hijinksensue.com/ | grep -o 'http://hijinksensue.com/comics/.*.jpg'`

HEADER="<html>\n<head>\n\t<title>Home</title>\n</head>"
CADHTML='<FONT FACE="Lucida Grande" SIZE=20><br>CTRL-ALT-DEL<br></FONT>\n<img style="padding: 5px\; border: 1px solid \#000000\;" src="CADURL">'
COMICJKHTML='<FONT FACE="Lucida Grande" SIZE=20><br>ComicJK<br></FONT>\n<img style="padding: 5px\; border: 1px solid \#000000\;" src="COMICJKURL">'
BUGHTML='<FONT FACE="Lucida Grande" SIZE=20><br>Bug<br></FONT>\n<img style="padding: 5px\; border: 1px solid \#000000\;" src="BUGURL">'
HIJINKSHTML='<FONT FACE="Lucida Grande" SIZE=20>HijiNKS ENSUE<br></FONT>\n<img style="padding: 5px\; border: 1px solid \#000000\;" src="HIJINKSURL">'
DILBERTHTML='<FONT FACE="Lucida Grande" SIZE=20><br>Dilbert<br></FONT>\n<img style="padding: 5px\; border: 1px solid \#000000\;" src="DILBERTURL">'
CYANIDEHTML='<FONT FACE="Lucida Grande" SIZE=20><br>Cyanide & Happiness<br></FONT>\n<img style="padding: 5px\; border: 1px solid \#000000\;" src="CYANIDEURL">'
XKCDHTML='<FONT FACE="Lucida Grande" SIZE=20><br>xkcd<br></FONT>\n<img style="padding: 5px\; border: 1px solid \#000000\;" src="XKCDURL">'

echo -e "$HEADER" > dailycomic.html
if [ $XKCDURL != "" ] $$ [ "$XKCDURL" != `cat .previouscm.txt | grep $XKCDURL` ]; then
	echo -e "$XKCDHTML" | sed "s|XKCDURL|$XKCDURL|" >> dailycomic.html
fi
if [ $CYANIDEURL != "" ] $$ [ $CYANIDEURL != `cat .previouscm.txt | grep $CYANIDEURL` ]; then
	echo -e "$CYANIDEHTML" | sed "s|CYANIDEURL|$CYANIDEURL|" >> dailycomic.html
fi
if [ $BUGURL != "" ] $$ [ $BUGURL != `cat .previouscm.txt | grep $BUGURL` ]; then
	echo -e "$BUGHTML" | sed "s|BUGURL|$BUGURL|" >> dailycomic.html
fi
if [ $COMICJKURL != "" ] $$ [ $COMICJKURL != `cat .previouscm.txt | grep $COMICJKURL` ]; then
	echo -e "$COMICJKHTML" | sed "s|COMICJKURL|$COMICJKURL|" >> dailycomic.html
fi
if [ $DILBERTURL != "" ] $$ [ $DILBERTURL != `cat .previouscm.txt | grep $DILBERTURL` ]; then
	echo -e "$DILBERTHTML" | sed "s|DILBERTURL|$DILBERTURL|" >> dailycomic.html
fi
if [ $HIJINKSURL != "" ] $$ [ $HIJINKSURL != `cat .previouscm.txt | grep $HIJINKSURL` ]; then
	echo -e "$HIJINKSHTML" | sed "s|HIJINKSURL|$HIJINKSURL|" >> dailycomic.html
fi
if [ $CADURL != "" ] $$ [ $CADURL != `cat .previouscm.txt | grep $CADURL` ]; then
	echo -e "$CADHTML" | sed "s|CADURL|$CADURL|" >> dailycomic.html
fi

I have googled for the fix for that error but I was unable to find anything that helped.
# 2  
Old 01-02-2011
What is in .previouscm.txt ? Does it exist what is the result of such a grep?
Code:
[ "$XKCDURL" != "`cat .previouscm.txt | grep $XKCDURL`" ]

In any case I would use double quotes to make sure the test has a single argument.
# 3  
Old 01-02-2011
The problem is you're using too many arguments. There are limits on argument lists and variable lengths, and if anything bash is unusually generous. You should keep both below a couple kilobytes in size.

This means statements that slurp in and/or compare entire massive blocks of data, like:

Code:
DILBERTURL=`entirety of everything`
$DILBERTURL != `cat .previouscm.txt | grep $DILBERTURL`

...should be avoided. Save the results directly into files with redirection, then use the diff command to see if there's any changes instead.
# 4  
Old 01-02-2011
Scrutinizer, Well until this works, .previouscm.txt is just a text file with random letters and numbers. Once this script works, I will add a few lines at the bottom writing all of the current url's to the text file, so if the URL appears in the text file it will do nothing.
When I grep it, nothing is returned, as shown in bash debug:
Code:
'[' http://imgs.xkcd.com/comics/audiophiles.png '!=' '' ']' 98109 '[' http://imgs.xkcd.com/comics/audiophiles.png '!=' '' ']'

I also tried the double quotes, didn't help.

Corona688, The Dilbert URL is 113 character, http://dilbert.com/dyn/str_strip/000...rip.sunday.gif, and that is too large?
If so, I should change the code to output each url to separate files and have the old urls in separate files and diff them?
# 5  
Old 01-02-2011
Quote:
Corona688, The Dilbert URL is 113 character, http://dilbert.com/dyn/str_strip/000...rip.sunday.gif, and that is too large?
Oh. No, it's not. All the backticking and cat-ing and grep-ing had me thinking you were dealing with an entire list of comics.
# 6  
Old 01-02-2011
Ah, ok. Damn, the error is still unexplained.
# 7  
Old 01-02-2011
You have $$ in the if statements -- did you want &&or ||.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[bash] cd: too many arguments

Hello everyone, Could someone please explain to me why I get cd: too many arguments when I select a dir that has one or more spaces in the name? This is the code #!/bin/bash tmp_loc=$(zenity --file-selection --directory) if ]; then exit 0 else location=${tmp_loc// /\\ } # this... (7 Replies)
Discussion started by: soichiro
7 Replies

2. Shell Programming and Scripting

Bash function failing with [: too many arguments

I'm reading Wicked Cool Shell Scripts. For some reason, the function pasted in below gives the error: ./inpath2: line 10: in_path() 4 { 5 cmd=$1 ourpath=$2 result=1 6 oldIFS=$IFS IFS=":" 7 8 for directory in "$ourpath" 9 do 10 if ; then 11 result=0 12 fi... (9 Replies)
Discussion started by: jakeroberts
9 Replies

3. Shell Programming and Scripting

Passing arguments to a bash script

Hi, I wanted to pass an argument to a bash script. So that the argument is used inside the awk command inside the bash script. I know the noraml way of passing argument to a bash script as below : sh myScript.sh abc Inside the bash script i can use like this myArg1=$1 wc $myArg But... (8 Replies)
Discussion started by: shree11
8 Replies

4. Shell Programming and Scripting

Bash script with arguments

Could someone help me with the script below? I am trying to make a script having just one arguement as a command and then it executes the appropriate code #!/bin/bash if then echo "Available commands:" echo "./exec.sh cmd1" echo "./exec.sh cmd2" elif then cmd1 =... (1 Reply)
Discussion started by: spiridakos
1 Replies

5. Shell Programming and Scripting

arguments in bash

This script moves all the doc files to a specified directory. I have managed to put an argument but the problem I am facing is putting the full path where the scripts are moving to, for example I want to run the script like this below ./loo -d then path where im moving the files (i.e ./loo -d... (3 Replies)
Discussion started by: elginmulizwa
3 Replies

6. Shell Programming and Scripting

arguments in bash

this script moves all the doc files to a specified directory....i have managed to put an argument but the problem im facing is puting the full path where the scripts are moving to for example i want to run the script like this below ./loo -d then path where im moving the files (i.e ./loo -d the... (2 Replies)
Discussion started by: elginmulizwa
2 Replies

7. Homework & Coursework Questions

BASH Environment Variables as arguments?

1. The problem statement, all variables and given/known data: Write a shell program called myenv which takes one argument. The argument should be the name of an environment variable, such as PATH HOME etc. myenv should print out the value of the variable given as the argument. If no argument is... (1 Reply)
Discussion started by: Helix
1 Replies

8. Shell Programming and Scripting

bash functions arguments

This script is called fuu; #!/bin/bash speak() { case $1 in 1)echo one ;; 2)echo two ;; 3)echo three ;; esac } speak exit 0 when i run fuu 2 i expect "two" like... (2 Replies)
Discussion started by: Tártaro
2 Replies

9. Shell Programming and Scripting

Make a list in bash out of arguments

Hello, I have a very stupid/simple problem, but for some reason I cannot figure out...and I need your help! I am writting a bash scrip that should be executed using "my_script X Y Z T" where X Y Z and T can be any string, but there can be any number of arguments. I want my script to do... (4 Replies)
Discussion started by: jolecanard
4 Replies

10. Shell Programming and Scripting

Bash Shell - # of arguments

Hi!, How can I check the number of arguments passed from the shell in a bash shell ? (1 Reply)
Discussion started by: DNAx86
1 Replies
Login or Register to Ask a Question