Bash Too Many Arguments Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you bash too many arguments if statement might have Meta Discuss the workings and policies of this site bash test too many arguments About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting bash script too many arguments ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7
Bash While Too Many Arguments
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 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: bash test negation 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 [ -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 4
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 too many arguments error in linux or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask Question _
Cd Too Many Arguments
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
If Grep Too Many Arguments
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 getting an error for too http://stackoverflow.com/questions/17653050/too-many-arguments-error-in-bash-script 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 zero length and if the other is http://unix.stackexchange.com/questions/238819/test-a-simple-script-but-i-keep-getting-an-error-for-too-many-arguments-on-line 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 of greater length than string2 30 echo "The First input string has a greater text l
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 us Unix & Linux Questions Tags Users Badges Unanswered Ask http://unix.stackexchange.com/questions/219525/error-c-sh-line-24-too-many-arguments-in-shell-program Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other http://gullele.com/too-many-arguments-error-in-bash-script-4-2/ 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 make a shell script to print the amount of time user was logged into the system but I encountered a too too many 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 - $lm` sh=`expr $ch - $lh` } else { sm=`expr 60 - $lm - $cm` sh=`expr $ch - $lh - 1` } fi exit 1 } if [ $ld -gt $cd too many arguments ] 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 bash -x c.sh is posted –identicon Jul 31 '15 at 18:01 1 Using Unix epoch (+%s) would be easier: last=$(date +%s -d "$(who | grep jeevansai | head -1 | grep -o '....-..-.. ..:..')") && now=$(date +%s) && m=$(((now-last)/60)) && echo "$((m/60)) hr $((m%60)) min" –yaegashi Jul 31 '15 at 18:12 2 Note that who gives several lines of output,
value="http://gullele.com/my-bookmarks-2/">My Bookmarks [: too many arguments error in bash script While writing bash script, if you got this error, check where you are making expression test like in if [ $somevar = "value"]; then .. if the $somevar is something you are getting it from another command [ say grep or ls] which happen to return a lot of results that are separated by space or something you end up having it being if [file1 file 2 file 3 = "value"]; then … The easiest solution for this is to enclose the variable in double quote like if [ -n "$somevar"]; then some more commands goes here Click here to see more on bash Happy BAsHing!!! What Others Are Reading Multiple keyword search in multiple directories bash script Bash directories coloring lost in unix when using ls Posted by gullele / 0 Comments Tagged withbash, Bash error in unix, script, too many arguments error Posted in Bash/Shell scripts Leave a Reply Cancel reply Your email address will not be published. Required fields are marked *Comment *Name * Email * Website Recent Posts Java Tomcat error: can not access a member of class with modifiers pass all the jars in classpath when compiling java Search and replace in vim Find Complementary numbers from array Java implementation Find longest palindrom from sequence of characters Recent Commentsgulleman on Find the pairs that makes K Complementary in the given array java solutiongulleman on Find the pairs that makes K Complementary in the given array java solutionReda on Find the pairs that makes K Complementary in the given array java solutionmtrad on Find the pairs that makes K Complementary in the given array java solutionDudley Nocera on Adding default option on the fly to select with jQuery, removing and some more