Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Bash function failing with [: too many arguments

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 1 Week Ago
jakeroberts jakeroberts is offline
Registered User
 
Join Date: Oct 2017
Last Activity: 10 October 2017, 8:39 PM EDT
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
I found the problem. I really, really hope someone can explain it. The top line does not work. The bottom one does. I manually typed the top line in. I copied and pasted the bottom line from the scripts supplied with the book. The quote marks look different. What in the world is going on here? I'm doing this on KDE Neon and in vim.


Code:
for directory in "$ourpath"
for directory in “$ourpath”

Sponsored Links
    #9  
Old Unix and Linux 1 Week Ago
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 22 October 2017, 2:06 AM EDT
Location: San Jose, CA, USA
Posts: 10,554
Thanks: 554
Thanked 3,697 Times in 3,154 Posts
Quote:
Originally Posted by jakeroberts View Post
I found the problem. I really, really hope someone can explain it. The top line does not work. The bottom one does. I manually typed the top line in. I copied and pasted the bottom line from the scripts supplied with the book. The quote marks look different. What in the world is going on here? I'm doing this on KDE Neon and in vim.


Code:
for directory in "$ourpath"
for directory in “$ourpath”

I think you have that backwards. The top line should work; the bottom line can't work. The shell command language has rules for constructing commands just like English has rules for constructing sentences. In English, sentences are terminated by a period, a question mark, or an exclamation point. The following is not an English sentence, because a semicolon is not a period, is not a question mark, and is not an exclamation point.

Code:
This is not a valid English sentence;

In the shell command language quoted strings are surrounded by double-quote characters (") or single-quote characters ('). And, the opening-double-quote character () and closing-double-quote character () is not a double-quote character (although in some fonts they look similar). Instead of being characters delimiting a double-quoted string, they are regular characters that are part of an unquoted string (or if there are whitespace characters between those quotes, part of multiple unquoted strings).
Sponsored Links
    #10  
Old Unix and Linux 1 Week Ago
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 22 October 2017, 9:44 PM EDT
Location: Simplicity
Posts: 3,782
Thanks: 311
Thanked 1,267 Times in 1,146 Posts
The top line has the normal ASCII quotes.
They work in the sense "protect the variable from splitting and globbing".
But in this case a splitting is wanted (as I said in post #7).

The "wrong" (alternate?) quotes in the second line might, after splitting into words, be added at the beginning of the first word and at the end of the last word. So might also spoil it, in this case the first and last path element.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bash Regexp failing: unexpected token `(' Eggie01 Shell Programming and Scripting 6 01-28-2014 05:20 AM
Need to call a function with arguments Vishal_dba Shell Programming and Scripting 7 12-17-2013 08:09 AM
bash read within function with arguments serverchief Shell Programming and Scripting 11 09-08-2011 12:34 PM
cat arguments to a function Random_Net Shell Programming and Scripting 3 08-10-2010 06:30 AM
sscanf function is failing jxh461 Programming 0 02-13-2007 10:10 PM



All times are GMT -4. The time now is 10:29 PM.