Fedora Linux Support Community & Resources Center
  #1  
Old 13th July 2006, 08:11 AM
Skunk Worx Offline
Registered User
 
Join Date: Apr 2006
Posts: 427
bash script breaking on spaces

Hi I am trying to write an automation script that uses smbclient to run commands on a smb share. Here is the trivial example script and the ouput. Obviously it is breaking the argument on spaces, even though it is quoted. Any help is appreciated.

Code:
#!/sbin/sh

echo "try one"
smbclient -U skunkworx -N -D / //localhost/Shared -c 'ls a'

smb_test ()
{
  smbclient -U skunkworx -N -D / //localhost/Shared -c $1
}

echo "try two"
smb_test 'ls a'

echo "try three"
smb_test 'ls'
...and the output :

Code:
$ sh ./smb.sh
try one
Anonymous login successful
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.22-1.fc5]
  a                                   D        0  Wed Jul 12 23:41:30 2006

                36825 blocks of size 2097152. 28223 blocks available
try two
session setup failed: NT_STATUS_LOGON_FAILURE
try three
Anonymous login successful
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.22-1.fc5]
  .                                   D        0  Wed Jul 12 22:56:47 2006
  ..                                  D        0  Thu Jul 13 00:04:56 2006
  a                                   D        0  Wed Jul 12 23:41:30 2006

                36825 blocks of size 2097152. 28223 blocks available
As can be seen, try two, when the argument is "ls a", breaks the space giving an error message.
__________________
registered linux user #192405
Note : i am usually not available in this forum Tuesday-Friday.

My Desktop Smolt

My Notebook Smolt
Small amount of personal info and notes about Fedora
Notes about Fedora, Java, JOGL and NeHe OpenGL Tutorials
Reply With Quote
  #2  
Old 13th July 2006, 08:27 AM
Spoon! Offline
Registered User
 
Join Date: Aug 2005
Location: Hell
Posts: 758
how about quoting it like
Code:
smb_test ()
{
  smbclient -U skunkworx -N -D / //localhost/Shared -c "$1"
}
Reply With Quote
  #3  
Old 13th July 2006, 10:50 AM
brahms Offline
Registered User
 
Join Date: Aug 2004
Location: Rio
Posts: 434
Or, as bash is passing the string twice:
Code:
smb_test ()
{
  smbclient -U skunkworx -N -D / //localhost/Shared -c \"$1\"
}
__________________
:cool:
Reply With Quote
  #4  
Old 14th July 2006, 04:36 AM
Skunk Worx Offline
Registered User
 
Join Date: Apr 2006
Posts: 427
Code:
smb_test ()
{
  smbclient -U skunkworx -N -D / //localhost/Shared -c "$1"
}
The "$1" works. Escaping the double-quotes does not. I could swear I tried this early on...sheesh.

Thanks.
__________________
registered linux user #192405
Note : i am usually not available in this forum Tuesday-Friday.

My Desktop Smolt

My Notebook Smolt
Small amount of personal info and notes about Fedora
Notes about Fedora, Java, JOGL and NeHe OpenGL Tutorials
Reply With Quote
Reply

Tags
bash, breaking, script, spaces

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
spaces in file names make my script choke unknowndevice Using Fedora 5 6th April 2009 11:59 PM
Convert bash script to perl script homey Programming & Packaging 1 2nd September 2006 04:24 AM
bash can't handle spaces? Firewing1 Using Fedora 3 23rd October 2005 08:34 PM


Current GMT-time: 18:33 (Thursday, 23-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Puerto Ayacucho - Altea Travel Photos on Instagram - Temple Terrace