Bash Script Error Too Many Arguments
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn bash if too many arguments more about Stack Overflow the company Business Learn more about hiring developers or posting too many arguments in shell script ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community linux too many arguments Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Too many arguments error in bash script up vote 6
Too Many Arguments Error In Linux
down vote favorite 1 I have modified this script to download songs from YouTube but I am getting the following error when I run it like this: sh youtube2mp3.sh https://www.youtube.com/watch?v=gpOJ6iu8fqQ Errors: youtube2mp3.sh: line 31: [: too many arguments youtube2mp3.sh: line 39: [: too many arguments youtube2mp3.sh: line 49: [: too many arguments Sorry but the system encountered a problem. The line numbers are referring to the three if cd too many arguments [ -f $video_title.$ext1 ] lines ... I thought I had the arguments ok as it worked in a previous version, but I'm stuck at this point — could someone explain what I need to do to correct it? address=$1 video_title="$(python youtube-dl $address)" ext1="flv" ext2="mp4" ext3="webm" if [ -f $video_title.$ext1 ] then ffmpeg -i $video_title.$ext1 "$video_title".wav lame "$video_title".wav "$video_title".mp3 rm $video_title.$ext1 "$video_title".wav else if [ -f $video_title.$ext2 ] then ffmpeg -i $video_title.$ext2 "$video_title".wav lame "$video_title".wav "$video_title".mp3 rm $video_title.$ext2 "$video_title".wav else if [ -f $video_title.$ext3 ] then ffmpeg -i $video_title.$ext3 -acodec libmp3lame -aq 4 "$video_title".mp3 rm $video_title.$ext3 else echo "Sorry but the system encountered a problem." fi fi fi bash shell share|improve this question edited Jul 15 '13 at 13:52 Jonathan Leffler 437k61507821 asked Jul 15 '13 at 11:20 frodo 4324826 6 Try double quoting the variable names in the test command. e.g. if [ -f "$video_title.$ext1" ] etc –user000001 Jul 15 '13 at 11:24 1 you run it in sh instead of bash. try to change that and report back. also put "" around your url and report back with that. –mnagel Jul 15 '13 at 11:29 add a comment| 2 Answers 2 active oldest votes up vote 6 down vote accepte
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more if grep too many arguments about hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered
Too-many-arguments Pylint
Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.
Integer Expression Expected Bash
Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Test a simple script but I keep http://stackoverflow.com/questions/17653050/too-many-arguments-error-in-bash-script getting an error for too many arguments on line 20 [closed] up vote 1 down vote favorite Greetings fellow UNIX&Linux users. I have an inquiry in regards to some code I have written in the bash script. My program was supposed to do the following: Write a script that will read two strings from the user. The script will perform three operations on the two strings: (1) Use the test command to see if one of the strings is of http://unix.stackexchange.com/questions/238819/test-a-simple-script-but-i-keep-getting-an-error-for-too-many-arguments-on-line zero length and if the other is of non-zero length, telling the user of both results. (2) Determine the length of each string and tell the user which is longer or if they are of equal length. (3) Compare the strings to see if they are the same. Let the user know the result. 6 #(1) Use the test command to see if one of the strings is of zero length and if the other is 7 #of non-zero length, telling the user of both results. 8 #(2) Determine the length of each string and tell the user which is longer or if they are of 9 #equal length. 10 #(3) Compare the strings to see if they are the same. Let the user know the result. 11 12 echo -n "Hello user, please enter String 1:" 13 read string1 14 echo -n "Hello User, please enter String 2:" 15 read string2 16 17 myLen1=${#string1} #saves length of string1 into the variable myLen1 18 myLen2=${#string2} #saves length of string2 into the variable myLen2 19 20 if [ -z $string1 ] || [ -z $string2 ]; then 21 echo "one of the strings is of zero length" 22 23 else 24 echo "Length of The first inputted string is: $myLen1" 25 echo "Length of The second inputted string is: $myLen2" 26 27 fi 28 29 if [ $myLen1 -gt $myLen2 ]; then #Determine if string1 is
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with http://unix.stackexchange.com/questions/219525/error-c-sh-line-24-too-many-arguments-in-shell-program us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top error ./c.sh: line 24: [: too many arguments in shell program up vote 2 down vote favorite I am trying to too many make a shell script to print the amount of time user was logged into the system but I encountered a too many arguments error. I tried many methods from the internet but none worked. Can someone spot the mistake? #!/bin/bash lt=`who | grep "jeevansai" | cut -c 35-39` lh=`echo $lt | cut -c 1-2` lm=`echo $lt | cut -c 4-5` ld=`who | grep "jeevansai" | cut -c 32-34` ch=`date +%H` cm=`date +%M` cd=`date +%d` fun() { if [ $cm -gt $lm ] then { sm=`expr $cm - too many arguments $lm` sh=`expr $ch - $lh` } else { sm=`expr 60 - $lm - $cm` sh=`expr $ch - $lh - 1` } fi exit 1 } if [ $ld -gt $cd ] then { if [ $ch -gt $lh ] then { fun } else { sh=`expr 24 - $lh + $ch` sm=`expr 60 - $lm + $cm` } fi } else fun fi echo "$sh hr $sm min" Output of bash -x c.sh: ++ who ++ grep jeevansai ++ cut -c 35-39 + lt='22:27 23:18' ++ echo 22:27 23:18 ++ cut -c 1-2 + lh=22 ++ echo 22:27 23:18 ++ cut -c 4-5 + lm=27 ++ who ++ grep jeevansai ++ cut -c 32-34 + ld='31 31 ' ++ date +%H + ch=23 ++ date +%M + cm=24 ++ date +%d + cd=31 + '[' 31 31 -gt 31 ']' c.sh: line 24: [: too many arguments + fun + '[' 24 -gt 27 ']' ++ expr 60 - 27 - 24 + sm=9 ++ expr 23 - 22 - 1 + sh=0 + exit 1 bash shell shell-script command-line command share|improve this question edited Jul 31 '15 at 18:10 Digital Trauma 3,3631817 asked Jul 31 '15 at 17:42 identicon 133 Could you please post the output of bash -x c.sh? –zwol Jul 31 '15 at 17:52 bash != c. You don't need all those { } in the if then else fi statements. (Conversely the function body does need them). –Digital Trauma Jul 31 '15 at 17:57 output of